Search code examples
iosuiviewcontrolleruinavigationcontrolleruinavigationbaruinavigationitem

iOS 11 - Display large title on UINavigationBar without using UINavigationController


I have UIViewController with UINavigationBar as a subview. No UINavigationController is involved.

I'm trying to display large titles. As the docs directed us to do:

myCustomNavigationBar.prefersLargeTitles = true
myCustomNavigationItem.largeTitleDisplayMode = .always

But it remains at the previous display mode (iOS 10 navigation mode).

When trying the same code with UINavigationController it works as expected. Is it not possible without UINavigationController or am I not approaching this correctly?


Solution

  • I don't know exactly at what point in the view life cycle you are including those lines of code, but if you execute them within the viewWillAppear(_ animated: Bool) method it works perfectly. I have checked it on Xcode 9 GM.

    EDIT: I'm sorry I did not read that you're not using a UINavigationController. An UINavigationBar without an UINavigationController have no sense. Please, add your UIViewController to an UINavigationController and you'll see the changes you want if you put those lines under viewWillAppear(_ animated: Bool) method

    :)