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]
您应该使用IBOutlet连接条形按钮项,然后可以使用边缘插入轻松添加间距:
barButton.imageInsets = UIEdgeInsetsMake(0,10,0,0)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.