iOS 5: Positioning Bar Button Item in a toolbar with Xcode/Storyboard

Electro-Bunny picture Electro-Bunny · Mar 21, 2012 · Viewed 20.4k times · Source

I have an existing toolbar in my View... when I drag a "Bar Button Item" into the tool bar it gets slammed to left side of the toolbar (I would like it to sit on the right edge). Attempting to drag the Bar Button only results in it being "gravity snapped" back to the left side. I see nothing in the size inspector that would allow me to align it to the right edge of the toolbar. The BarButton width can be changed, but seemingly nothing else. Can anyone please give me an idea of how to move it to the right?

I will confess that I have a rookie/rudimentary understanding of (or lack thereof) Xcode/storyboarding gleaned from watching CS193p lecture videos (but I have not been able to relocate the lecture describing positioning within toolbars or pertinent documentation... a link would be welcomed.)

Answer

jrturton picture jrturton · Mar 21, 2012

Drag in a flexible space item to the left of your UIBarButton. Put another one to the right if you want it centered, and so on.

The pertinent CS193p lecture is lecture 7 (the iPad one), he covers UIToolbar at the start of that.

enter image description here