rounak
rounak

Reputation: 9397

How do I add a square button with a '+' on it to uinavigationbar?

Like the right button shown in this image. https://i.sstatic.net/D2Q61.jpg Is it a default button provided by apple? If yes then how do I add it to the navigationBar?

Upvotes: 0

Views: 435

Answers (2)

Moshe
Moshe

Reputation: 58097

Yes, that [+] button is a default button, provided by Apple. It is the UIBarButtonSystemItemAdd identifier.

Here's some code to get it working:

// Create the Add button

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(someMethod)];

// Display it

self.navigationItem.rightBarButtonItem = addButton;

//  Release the button

[addButton release];

You will need to define someMethod, so your program has code to run when the button is tapped.

Upvotes: 1

MarkPowell
MarkPowell

Reputation: 16540

UIBarButtonItem *addButton = 
  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
  target:self
  action:@selector(myCallback:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];

Upvotes: 3

Related Questions