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.