How to change the text of UIBarButtonItem programmatically?
Try this:
UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear" style:UIBarButtonItemStyleBordered target:self action:@selector(yourMethod:)];
- Create an
IBOutlet
for theUIBarButtonItem
, outToMyButton in this example - synthesize in
.m
outToMyButton.title = [NSString stringWithFormat:@"%i",myInt]; // or any NSString init
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
.