views:

335

answers:

1

I've read this article: http://stackoverflow.com/questions/1225457/change-the-text-of-a-uilabel-uibarbuttonitem-on-a-toolbar-programmatically

But it seems not working for my auto-hide toolbar?
I also tried "barbuttonItem.title" to set the text, failed too.

Any idea? Much thanks!

A: 

Are you creating the button in Interface Builder? Make sure that the identifier is set to Custom, otherwise you will not be able to change the title.

Select the UIBarButtonItem in Interface Builder, open the inspector (Command + Shift + I), and select "Custom" under the dropdown next to "Identifier".

Pyro2927
how to do this in program? I don't use the IB at all, thx.
Does your "set to Custom" mean "initWithCustomView"?If so, my item was already set to Custom. like this: percentage = [[UILabel alloc] init]; percentage.text = @"HELLO"; UIBarButtonItem *percentageBarItem = [[UIBarButtonItem alloc] initWithCustomView:percentage]; I want to keep it changeable after putting it on the toolbar.
sorry, I don't know how to make up in comment.../_\
If you are simply using text, I would recommend calling- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)actionThen you can change the title later with ease.
Pyro2927
Thanks! It works perfectly. Could I ask one more question? Howto change the value of UIBarButtonItem slider in the same condition(i.e., auto-hide toolbar)