I have a UIToolbar
at the top of my view, and it needs to be resized in an animation. The toolbar contains:
- A
UIBarButtonItem
using system itemUIBarButtonSystemItemAdd
(the '+' button) - A
UIBarButtonItem
using a custom view (the title) - A
UIBarButtonItem
using the styleUIBarButtonItemStyleBordered
(the 'Edit' button)
I am adding these buttons using a spacer between each, which keeps the title in the center:
[toolbar setItems: @[addButton, spacer, titleButton, spacer, editButton] animated:NO];
The toolbar resizes just fine, and the two buttons keep their locations pinned to the outside edges. However, the title button does not stay in the center of the toolbar. Instead, it seems to pin its right edge to the same location, creating a space on its left side. During the animation, this give the impression that it is sliding right.
To be clear, I do want the title bar to keep its same width - I do not want it to expand as the toolbar grows. But I need the title to stay in the center of the toolbar.
Since a UIBarButtonItem
is not a UIView
, I can't (?) use the autoresizingmask
functionality.
How do I keep the title in the center of the toolbar?
Additional Info
This might be because the Add and Edit buttons have different widths - when I add only the title (with a spacer either side), the behavior is correct.