Search code examples
iosuinavigationbaruinavigationitemuinavigationcontroller

UINavigationBar title NOT centered horizontally


I have a a storyboard with a Navigation Controller and two View Controllers stacked on top of it as such: enter image description here

Somehow (and for reasons I would like to understand) the length of the text in the UINavigationBar of the first UIViewController is affecting the centering of the text in the UINavigationBar of the second View Controller. Why is this happening and how do fix it?

Here is an example with a shorter text length in the first view controller:

enter image description here

All I did was change the text from "Privacy Privacy Privacy" to "Privacy" in the UINavigationItem in IB.

Why is this happening and what is the fix? Can this be fixed in IB without code?


Solution

  • It is possible through storyboard, you achieve that by setting the back button for the navigation item. Check the attached screenshot.

    Screenshot