Aligning UIToolBar items Aligning UIToolBar items ios ios

Aligning UIToolBar items


Add two UIBarButtonSystemItemFlexibleSpace items to your toolbar, to the left and right of your items

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];[toolbar setItems:[NSArray arrayWithObjects:flexibleSpace, settingsButton,deleteButton,aboutButton, flexibleSpace, nil]];

Adding these as you would any other toolbar items will distribute space evenly between the two of them.


This can also be done right from a storyboard.

Just drag and drop items in the toolbar, and turn some of them into flexible or fixed space to get the desired effect. See the two examples below.

Evenly spaced

Centered


In Xamarin iOS

Right aligned:

yourBar.SetItems(new [] { new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace), yourButton }, false);

Center Aligned:

var flexibleSpace = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);yourBar.SetItems(new [] { flexibleSpace, yourButton, flexibleSpace}, false);