Reputation: 1192
I have a toolbar at the top of my app. I changed the height programmatically to make it a bit bigger.
var constH = NSLayoutConstraint(item: toolbar, attribute: NSLayoutAttribute.Height,
relatedBy: NSLayoutRelation.Equal, toItem: nil,
attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 64)
toolbar.addConstraint(constH)
But now I have the problem when I add bar button items via storyboard, it automatically centers them vertically. Only the standard items stay at the bottom. How to solve?
[Please answer in Swift]
Upvotes: 1
Views: 1427
Reputation: 457
You can do this for programmatically added items as well: (Code in Swift3)
let search = UIBarButtonItem(image: UIImage(named: "Search"), style: .plain, target: nil, action: nil)
search.imageInsets = UIEdgeInsetsMake(10, 0, 0, 0)
navigationItem.rightBarButtonItem = search
Upvotes: 0
Reputation: 1194
You should hook up your bar button items using IBOutlets, then you can easily add spacing using edge insets:
barButton.imageInsets = UIEdgeInsetsMake(0,10,0,0)
Upvotes: 2