Lorenzo Ang
Lorenzo Ang

Reputation: 1318

UINavigationBar is off center?

So I recently set up an app with a navigation bar except it's refusing to stay in the middle of the screen. The title is moved slightly to the right and the right-most button is hidden off screen. I've tried everything from resizing, to deleting it and re adding it, to cleaning, etc... and nothing works. Any idea why this might be? :\

This is what it looks like when run on the simulator vs the Storyboard enter image description here

Upvotes: 0

Views: 62

Answers (1)

i_am_jorf
i_am_jorf

Reputation: 54600

The title is centered, but the UINavigationBar is 600px wide. Your screen is not that wide. You need to add layout constraints that resize the toolbar appropriately for the containing view.

You need to add layout constraints. CTRL+DRAG from the UINavigationBar to its parent view (in the left hierarchical tree-view tool window):

enter image description here

And add the following constraints (hold ALT and SHIFT while selecting):

  • Leading Space to Container
  • Trailing Space to Container
  • Top Space to Top Layout Guide

Upvotes: 1

Related Questions