Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add another button to navigation bar

I'm modifying an app and this app has some buttons in its navigation bar, I wanted to add another button or Bar Button item by dragging it to the hierarchy but it seems I can't add it as a child to navigation bar, I wanted to ask if you have any solutions to this, here's a snapshot of the hierarchy of the storyboard, I want to add another Bar Button Item or another Button to the Navigation item.
Thanks
enter image description here

like image 694
m0j1 Avatar asked Nov 17 '15 18:11

m0j1


People also ask

How do I add more buttons to my navigation bar?

From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen. Note: This option will also affect the location you swipe when using Swipe gestures.

How do I add content to my navigation bar?

Use <h4> tag to add the heading for the navigation bar. Use <ul> tag to define unordered (unnumbered) lists. Use <li> tags within the <ul> tag to add list items to the unordered list. Use <a> tag to add a hyperlink to any content on the web page.


1 Answers

So I've just created a blank project and I can do this:

enter image description here

I've also done stuff like this before where I actually use a UIButton rather than a bar button item gaining some extra customisability. Just make sure that you set an outlet to the button and in the view controller call self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.customButton];:

enter image description here

You can have multiple right bar button items and if they overlap the title (if you have one) then they are essentially clipped. From my understanding, you can have as many buttons as you like until the space is gone (which can vary depending on the device, obviously). Relevant docs:

This array can contain 0 or more bar button items to display on the right side of the navigation bar. Items are displayed right-to-left in the same order as they appear in the array. Thus, the first item in the array is the rightmost item and other items are added to the left of the previous item.

If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the left side of the bar are not displayed.

An example with lots of buttons:

enter image description here

Programatically you can add buttons using:

navigationItem.rightBarButtonItems = [aButton, anotherButton, awesomeButton]

Just make sure you test that the smallest device you target will still provide a good UX for the user if you add lots of buttons.

like image 74
Gordonium Avatar answered Oct 20 '22 04:10

Gordonium