tags:

views:

876

answers:

4

In UIKit, UIBarButtonItem has a property called possibleTitles. How is that being used?

+13  A: 

I looked at the documentation and it said that it was referenced in the AccelerometerGraph demo. So I took a look at the demo.

It looks like before you add it to the bar, you can set the possibleTitles property to a set of strings that the button may display. I assume that this is so that the button takes the width of the widest string, so when you change the title the width of the button doesn't change.

Ed Marty
+1  A: 

Just so you know, you can still change the button's title with the title property, as it is a subclass of UIButton.

Brenden
Guess this was a typo, but it's a subclass of UIBarItem in 3.0 at least.
petert
+1  A: 

Ed got it. That's exactly what I use it for!

Joe D'Andrea
A: 

I wrote a little code to test this out and it's like Ed says, the button will be as wide as it needs to be to fit the longest string in the NSSet given to possibleTitles

UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"Bye"
            style:UIBarButtonItemStyleBordered
            target:self
            action:@selector(sayGoodnight)];
myButton.possibleTitles = [NSSet setWithObjects:@"So Long", @"Farewell", @"Auf Wiedersen, Good Night", nil];
[self setToolbarItems:[NSArray arrayWithObjects:myButton, nil] animated:NO];
[myButton release];

The button is set wide enough to fit "Auf Wiedersen, Good Night".

nevan