Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically changing the identifier property of UIBarButtonItem

Through Interface Builder I have the ability to change the Identifier of a UIBarButtonItem to something like "Add" (or "Undo", "Redo" etc...). This gives my button a nice "+" image.

How can I set this programatically? The UIBarButtonItem does not accept a "setIdentifier" message.

like image 701
rein Avatar asked Jul 11 '09 08:07

rein


1 Answers

Once constructed, a UIBarButtonItem's "Identifier" can not be modified. However, the UI can be changed by replacing the button with a programmatically constructed variant. For example:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                                           target:self 
                                                                           action:@selector(doAddAction:)];
like image 177
rein Avatar answered Oct 27 '22 01:10

rein