iosswiftuinavigationcontrollerpreferslargetitles

UINavigationBar large title not resizing when performing segues


I've used this code in my main UIViewController to have a large title:

navigationController?.navigationBar.prefersLargeTitles = true

But I don't want that to happen in every view, indeed I just want that large title in my main view.

So, reading online, I've seen that to achieve this I needed to add this in my views in which I did not want that large title:

navigationController?.navigationItem.largeTitleDisplayMode = .never

But that's not really working as expected.

The result that I'm getting is that when I perform a segue, the title disappears, but the navigation controller maintains the same size as if there was a large title inside it.

What could be wrong with my implementation?

iOS 12.1 Beta 3
Xcode 10.1 Beta 2


Solution

  • You should change largeTitleDisplayMode to .never for the navigationItem of your view controller instead.

    navigationItem.largeTitleDisplayMode = .never
    

    Alternatively, if you're working with storyboards, you can set the Large Title option to Never inside the Attributes inspector of your navigation item:

    Navigation Item settings - Large Title set to Never