How to break a long big title in iOS 11?

I am trying to use the new big title system in iOS 11 using Swift. When the title gets too long (see Example Image), it adds ... instead of breaking the line or reducing the size of the text. How to add line break?

Example image with long title

Here is the code I use to customize the header:

self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: MyGlobalVariable.themeMainColor]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 22)]
navigationItem.title = "Search by Name"
+4
source share
1 answer

Try the following:

for navItem in (self.navigationController?.navigationBar.subviews)! {
    for itemSubView in navItem.subviews {
        if let largeLabel = itemSubView as? UILabel {
            largeLabel.text = self.title
            largeLabel.numberOfLines = 0
            largeLabel.lineBreakMode = .byWordWrapping
        }
    }
}

It worked for me.

enter image description here

+1
source

Source: https://habr.com/ru/post/1686448/


All Articles