Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Blank Space Between Nav Bar Items?

I've spent several hours on trying to figure this out to no end. My last option is to just create blank labels to create space, but I feel like their is a more cleaner way.

Basically I have three buttons and we're trying to create fixed space between them for neatness. Each button is programmatically added.

I found this code:

UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = 20.0f; // or whatever you want

(Source)

But how do you assign this piece of code to a certain button?

like image 231
Camerz007 Avatar asked Mar 05 '14 23:03

Camerz007


People also ask

How do I add a space between navbar items?

For adjusting space between your navbar elements you need to give padding. You can also use margin, but I don't recommend this. Add the padding as much as you can. Also, use Chrome Developers Tool(Inspect element) to see the perfect padding for your element.

How do you space out a navigation bar in HTML?

If you want some space at the beginning and end, simply change justify-content: space-between; to justify-content: space-around; .

How do you put a space between navbar elements in bootstrap5?

Simply add px-3 (or a number of your choice) inside the class="" attribute of your chosen nav-item.

How do I create a navbar border?

Add the border property to <ul> add a border around the navbar. If you also want borders inside the navbar, add a border-bottom to all <li> elements, except for the last one: Home.


1 Answers

Its possible you're confused. You don't assign this code to a button. That code creates a button of type UIBarButtonSystemItemFixedSpace. So, do what the answer you linked to says. Create the fixed & flexible UIBarButtonItems (along with the other buttons you have), then set them on your navigation bar. In this case they would appear in the top left area of your navigation bar (via leftBarButtonItems):

// Create "Normal" buttons items:
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"1" style:UIBarButtonItemStylePlain target:Nil action:nil];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithTitle:@"2" style:UIBarButtonItemStylePlain target:Nil action:nil];    
UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithTitle:@"3" style:UIBarButtonItemStylePlain target:Nil action:nil];

// Create "Spacer" bar button items 
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = 20.0f; // or whatever you want
UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

self.navigationItem.leftBarButtonItems = @[button1, fixedItem, button2, flexibleItem, button3];

Additionally, if you had a toolbar you could use the toolbar's items property:

self.toolbar.items = @[button1, fixedItem, button2, flexibleItem, button3];
like image 143
Aaron Avatar answered Sep 30 '22 12:09

Aaron