The placement of Bar Button Item
in UIToolBar
uses Fixed Space Bar Button Item
and Flexible Space Bar Button Item
to adjust the space between items.
On the storyboard, you can place items on both sides by inserting the Flexible Space Bar Button Item
as shown below.
The program does the same thing.
An instance of UIToolBar
is toolBar
.
//Left Bar Button Item
letitem1 = UIBarButtonItem(title: "Item1", style: UIBarButtonItemStyle.Plain, target:nil, action:nil)
// Flexible Space Bar Button Item
let flexibleItem = UIBarButtonItem (barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target:nil, action:nil)
// Right Bar Button Item
let item2 = UIBarButtonItem(title: "Item2", style: UIBarButtonItemStyle.Plain, target:nil, action:nil)
// Arrange the three.
let items = [item1, flexibleItem, item2]
// Replace array with UIToolBar property items
toolBar.items=items
© 2024 OneMinuteCode. All rights reserved.