Search code examples
iosxcodeswiftuitoolbar

How to put a Bar button item to the bottom of a toolbar?


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]

enter image description here


Solution

  • 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)