Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add multiple buttons to navigation bar in storyboard

Tags:

I wonder if this can be achieved using Storyboard IB:

self.navigationItem.leftBarButtonItems = @[barButton1, barButton2]

EDITED:

The purpose is to preserve the benefits of using storyboard and if it's possible without using any lines of code.

EDIT #2:

Based on this answer I experimented and saw that it is possible to link the Title View property of the Navigation Item to a Toolbar enter image description here

but it looks to me like a hack (and I might want to preserve the Title as well):

enter image description here

Any better idea?

like image 303
user623396 Avatar asked Mar 20 '14 10:03

user623396


People also ask

How do I add a navigation bar in Swift storyboard?

Go to the Storyboard. Select the View Controller and in The Editor menu select Embed in -> Navigation Controller. Next, drag a Bar Button from the Object Library to the left side of the Navigation Bar and name it "Left Item". Repeat this for the right side and name it "Right Item".


2 Answers

There a way to add a view to navigationItem. Than add buttons or labels you need to the view.

enter image description here

enter image description here

like image 159
JerryZhou Avatar answered Oct 19 '22 03:10

JerryZhou


Can use below code :

UIBarButtonItem *btnShare = [[UIBarButtonItem alloc] initWithCustomView:self.backbtn]; UIBarButtonItem *btnRefresh = [[UIBarButtonItem alloc] initWithCustomView:self.testbutton2];    [self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:btnShare,btnRefresh, nil]]; 
like image 36
Niranjan kumar Avatar answered Oct 19 '22 01:10

Niranjan kumar