How to Present Different Navigation Title When Large Title Collapse

How to present different navigation title when large title collapse?

You can observe the bounds of the navigationBar and change the title using a check on the height of the navigationBar.

1. for Small Title, height of navigationBar = 44

2. for Large Title, height of navigationBar > 44

class VC: UIViewController {
var observer: NSKeyValueObservation?

override func viewDidLoad() {
super.viewDidLoad()
self.observer = self.navigationController?.navigationBar.observe(\.bounds, options: [.new], changeHandler: { (navigationBar, changes) in
if let height = changes.newValue?.height {
if height > 44.0 {
//Large Title
self.title = "Large Title"
} else {
//Small Title
self.title = "Small Title"
}
}
})
}
}

Sample Image

NavigationBar large title not collapse when I have custom image/view under tableView iOS 13

So, after a long search and a lot of tries, finally I figure out in a different way:

tblSettings.backgroundView = UIImageView(image: UIImage(named: "yourImageName"))

Setting backgroundView to UITableView it will allow navigation bar to animate properly to large and normal titles.

Hope this will someone!

Large title doesn't appear large

After some messing around this seems like a glitch in Xcode (for me at least)

I've managed to fix it by adding

self.navigationController?.navigationBar.prefersLargeTitles = true

in

override func viewWillAppear(_ animated: Bool)

Hope this might be useful for other people in the future



Related Topics



Leave a reply



Submit