views:

434

answers:

1

How would I be able to set the position of a UIBarButtonItem? Like, I would like to set it to be on either the very right of a UIToolbar or the very left depending on a state.

Thank you.

+1  A: 

You do not set directly the position of a UIBarButtonItem in an UIToolbar. Instead you defined the items' order and put flexible space on the left or on the right.

What you can do is:

  • Create the UIBarButtonItem you want to place (button 1).
  • Create an UIBarButtonItem of type UIBarButtonSystemItemFlexibleSpace (button 2).
  • If you want to put the button on the left, create an array with (button 1) and (button 2) and pass it to the UIToolbar by using the setItems:animated: method.
  • If you want to put the button on the right, create an array with (button 2) and (button 1) and pass it to the UIToolbar by using the setItems:animated: method.
Laurent Etiemble