Is it possible to have the new large titles for navigation bars in iOS 11 show multiple lines? The App Store app does this but I can't find anything in the current documentation to do this. The standard behavior just shows one line with ellipsis if it's too long.
Multiple lines for large titles in navigation bars in iOS 11
Asked Answered
did you get any solution for this ? –
Nuclei
If it can help here's what I did a another thread : https://mcmap.net/q/746741/-how-to-line-break-long-large-title-in-ios-11 –
Musetta
Add following code into viewWillAppear:
navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationItem.largeTitleDisplayMode = .automatic
self.title = "Hello big text, For navigation large style bar"
navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font : UIFont.preferredFont(forTextStyle: .largeTitle)]
var count = 0
for item in(self.navigationController?.navigationBar.subviews)! {
for sub in item.subviews{
if sub is UILabel{
if count == 1 {
break;
}
let titleLab :UILabel = sub as! UILabel
titleLab.numberOfLines = 0
titleLab.text = self.title
titleLab.lineBreakMode = .byWordWrapping
count = count + 1
}
}
}
self.navigationController?.navigationBar.layoutSubviews()
self.navigationController?.navigationBar.layoutIfNeeded()
Facing issue with back button will update soon..
Any update for the back button issue? I can only get it to work in the viewdidappear, which only applies after the view is visible and thus looks blocky. –
Daynadays
maybe you can just use break where you've assigned the count. –
Verger
this does not work, the label goes multiline but nav bar does not increase its height @Dragrope –
Narvaez
Agreed with @ShahzaibQureshi –
Ploch
There is a way to do this simply by using a non-public API. Use at your own risk:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Thunderbox Entertaiment"
navigationItem.enableMultilineTitle()
}
}
extension UINavigationItem {
func enableMultilineTitle() {
setValue(true, forKey: "__largeTitleTwoLineMode")
}
}
private api may lead to unpredictable results like crashes and review rejection –
Gynaecology
© 2022 - 2024 — McMap. All rights reserved.