0

I am trying to show my long text on Navigation Bar in 2 lines. I am using LargeTitles.

What I need is this https://i.stack.imgur.com/Yb85L.png // sorry cant post picture.

Image was taken from this post

I have tried a lot of examples and have achieved in showing the title in 2 lines. but the problem is that when I open a ViewController with a long title it jumps to adjust the title. Following is my code I have tried. I want to avoid jumping (increasing) and show the multiline text as same as it if using single line text. the normal effect.

func multiLineHeader() {
        if #available(iOS 11.0, *) {
            if let subviews = self.navigationController?.navigationBar.subviews {
            for navItem in subviews {
                for itemSubView in navItem.subviews {
                    if let largeLabel = itemSubView as? UILabel {
                        if largeLabel.canFitInSingleLine() { return }
                        largeLabel.numberOfLines = 2
                        largeLabel.lineBreakMode = .byWordWrapping
                        largeLabel.sizeToFit()
                        self.navigationController?.navigationBar.frame.size.height += largeLabel.frame.height
                        self.navigationController?.navigationBar.layoutIfNeeded()
                    }
                }
            }
        }
    }
}

I am calling this from viewDidAppear(). I tried calling from viewDidLoad() and viewWillAppear() does not work event title is not in 2 lines. as it was when called from viewDidAppear().

If there is anything which is not clear, comment and I will add more details.

Zohaib Brohi
  • 41
  • 1
  • 3

1 Answers1

0

This is not a solution to solve the multiline jump effect.

My question was based on the multiline title which I saw in the App Store(app) which did not have a jump effect. After a while when I dig deep into it. I found out that even in the App Store there is a jump effect on some screens and in some places App Store is using view rather than navigation bar.

For example, if you go to the App Store and search for Thunderbox entertainment.

1) Go to one of its apps and then click on company name to see all apps you will see a navigation bar with jump effect.

2) If you open the company profiles directly from the search screen you won't see any jump effect.

Zohaib Brohi
  • 41
  • 1
  • 3