0
votes

I am trying use UIBarButtonItem property possibleTitles to set the size of a button, my problem is that my UINavigationBar and UIBarButtons are created in Interface Builder (XIB file) and it looks like possibleTitles needs to be set before the UIBarButtonItems are added to the UINavigationBar.

// FROM viewDidLoad
[self setNavBarItem:[[navBar items] objectAtIndex:0]];
[self setButtonStart:[navBarItem leftBarButtonItem]];

NSSet *buttonSizes = [NSSet setWithObjects:@"IT",@"FLIP",@"WARPCOIL", nil];
[[self buttonStart] setPossibleTitles:buttonSizes];

Does anyone know if you can do this if the UINavigationBar and UIBarButtonItem are created in IB, or do I need to specify the view programmatically via loadView to gain finer control over the elements?

EDIT_001:

One solution might be to add the UINavigationBar in IB (with an IBOutlet to connect it to Xcode) and then create and add the UIButtonBarItems programatically in xcode. That way I can set possibleTitles before I add the buttons to the UINavigationBar.

1

1 Answers

3
votes

The UIBarButtonItem changes width based on Title when the width property is set to zero in IB.

To get a fixed width, set the Title property to your longest word (WARPCOIL in your case), then set the width property so the word fits.

When you change the title in code the button will then stay at that fixed width.