How to add four or more navigation bar buttons in your iOS App XCode Project

I assume that you have added navigation controller through Editor > Embed In > Navigation Controller in xib (or formally nib) file in your XCode Projects’ Storyboard

 
Problem:

 
Then for example you have added Action button for Tweet Sheet at Left & Menu button at right & Title button in middle.

 
But this three items doesn’t allowing you to add additional button at second left position.

Through this additional functionality you can enrich your app’s usp (unique selling point) or usability.

 
Reason:

 
It turns out, this is a limitation of Interface Builder. It will only let you configure a single left and right bar button item in a navigation bar. Not to worry though, you can still configure your remaining items in code. For example,

 
Solution:

 
Add following code in viewDidLoad function in your View Controller’s Header file i.e .h file

 

UIBarButtonItem *email = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(someAction)];
    self.navigationItem.leftBarButtonItems = [self.navigationItem.leftBarButtonItems arrayByAddingObject:email];

 
So now your viewDidLoad function will look like this:

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Add a compose button alongside the existing left bar button item from the storyboard.
    UIBarButtonItem *email = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(someAction)];
    self.navigationItem.leftBarButtonItems = [self.navigationItem.leftBarButtonItems arrayByAddingObject:email];
}

 
Now you can write method for your added button like this:

 

- (IBAction)someAction
{
    // Your code here...
}

 
Further Reading:

 

How to add four or more UIBarButtonitem at navigation bar with custom image through code?

 
Hope it helps,

 
Thanks & Regards
Mandar Apte

Mandar Apte

This website contains a design articles blog by Mandar Apte. He writes and shares his iOS development, graphic, web, & animation film design experience through articles. Mandar is Mumbai based multi-disciplinary designer with expertise in UI, UX, Logo, Symbol, and Brand Identity design. He is an alumnus of Sir J. J. Institute of Applied Art, Mumbai. He currently runs his studio in the heart of the city of Mumbai.

One thought on “How to add four or more navigation bar buttons in your iOS App XCode Project

  1. Thanks very much, I have three items on my navigation bar, two buttons on the left and right side of it and an image in the center. I followed your guide but it added the fourth button on the right side of the left button. I wanted to ask if you can help me on get it to the left side of the left button. And if you can also help me on setting a texture for this fourth button.
    Thanks very much for your help.

Leave a Reply

Your email address will not be published. Required fields are marked *