I know how to use initWithCustomView to create and add a UIBarButtonItem with a custom view in code. But I prefer to do things like this in Interface Builder when I can. I can't seem to find any way to create a custom UIBarButtonItem and set the custom view.
Ios – Can you create a UIBarButtonItem with a Custom View in Interface Builder
interface-builderios
Related Topic
- Ios – How to load a UIView using a nib file created with Interface Builder
- Ios – How to make a UITextField move up when the keyboard is present – on starting to edit
- IOS – UIBarButtonItem Identifier – option to create “settings” cogwheel button
- Ios – How to animate constraint changes
- Ios – “Width equals height” constraint in Interface Builder
- Ios – UIScrollView Scrollable Content Size Ambiguity
- C++ – Is it possible to generate types with all combinations of template arguments
- Ios – @IBDesignable error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed
Best Answer
OK, I eventually figured out how to do it.
If you drag a view onto a NavigationItem that will create a UIBarButtonItem that is initialized with that custom view and it links it to the right bar button. Alternatively you can drag the view onto a bar button item that is inside a Navigation Item. It will not work for a bar button item that is not inside a Navigation Item.
To create a left bar item with custom view, it is a bit trickier. A bar button item inside a navigation item is hardcoded to be the right side item. What I did was add another navigation item temporarily to the top level of the xib file. Then drag the view onto the navigation item which creates the bar button item inside this navigation item. Move the bar button item out of the navigation item (to the top level of the xib). Then I can delete the navigation item I added so then I have a free standing bar button item initialized with a custom view. You then have to add the link from the leftBarButtonItem outlet of the real navigation item to this bar button item yourself.