Search code examples
iosxcode6uinavigationitem

Navigation Title does not center?


Quick question: the text of my Navigation Title does not center by default (unless I am running a 6 Plus), should it based on what type of phone it is displayed on? The title shows up centered in the storyboard (using the Universal storyboard size), however, if I look on Preview or the actual phone (4S, 5, and 5S), the title is pushed all the way to the right. Do I actually have to attempt to use AutoLayout or is there a setting in the Attribute Settings that I am missing?

enter image description here


Solution

  • Without Auto Layout, the UI will appear in device/Simulator at exactly the same position as in storyboard, measured in points.

    In storyboard, the scene is 600*600, and the title centers horizontally, so the horizontal ordinate of the title's center is 300, maybe at letter 'p'. Any iPhone earlier than 6/6Plus has the width of 320, as you can see in your screen shot, the right edge ends a little farther than 'p'.

    Auto Layout can help you and in my experience it pays off to grasp it.

    First, select Navigation Bar, then in the menu, choose Editor->Align->Horizontal Center in Container, that's all you have to do.

    You will notice a warning arises, it won't bother you. You can ignore it until you understand Auto Layout.

    I highly recommend this tutorial