Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple lines for large titles in navigation bars in iOS 11

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.

enter image description here

like image 454
Berry Blue Avatar asked Oct 05 '17 05:10

Berry Blue


Video Answer


1 Answers

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..

like image 166
Rahul_Chandnani Avatar answered Sep 20 '22 06:09

Rahul_Chandnani