BarButtonItem EdgeInsets 不起作用
BarButtonItem EdgeInsets doesn't work
我正在尝试在按钮之间的导航栏 rightBarButtonItems 的右侧添加一个填充,但它现在可以正常工作了。
这是带有给定插图的按钮创建代码:
lazy var previewBarButtonItem: UIBarButtonItem = {
let buttonItem = UIBarButtonItem(title: "Preview", style: .plain, target: self, action: #selector(handlePreview))
buttonItem.tintColor = UIColor.black
buttonItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14)], for: .normal)
buttonItem.imageInsets = UIEdgeInsetsMake(0, -15, 0, 15)
return buttonItem
}()
override func viewDidLoad() {
super.viewDidLoad()
setupRightNavItems()
}
fileprivate func setupRightNavItems () {
navigationItem.rightBarButtonItems = [submitBarButtonItem, previewBarButtonItem]
}
你能提示一下为什么这不起作用吗?
谢谢
我设法解决了这个问题,只是在栏按钮项之间添加了一个固定空间,如下所示:
1) 删除任何 EdgeInsets
2) 添加以下固定 space:
fileprivate func setupRightNavItems () {
let spacing = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
spacing.width = 25 //change to your desired space width
navigationItem.rightBarButtonItems = [submitBarButtonItem, spacing, previewBarButtonItem]
}
我正在尝试在按钮之间的导航栏 rightBarButtonItems 的右侧添加一个填充,但它现在可以正常工作了。
这是带有给定插图的按钮创建代码:
lazy var previewBarButtonItem: UIBarButtonItem = {
let buttonItem = UIBarButtonItem(title: "Preview", style: .plain, target: self, action: #selector(handlePreview))
buttonItem.tintColor = UIColor.black
buttonItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14)], for: .normal)
buttonItem.imageInsets = UIEdgeInsetsMake(0, -15, 0, 15)
return buttonItem
}()
override func viewDidLoad() {
super.viewDidLoad()
setupRightNavItems()
}
fileprivate func setupRightNavItems () {
navigationItem.rightBarButtonItems = [submitBarButtonItem, previewBarButtonItem]
}
你能提示一下为什么这不起作用吗?
谢谢
我设法解决了这个问题,只是在栏按钮项之间添加了一个固定空间,如下所示:
1) 删除任何 EdgeInsets 2) 添加以下固定 space:
fileprivate func setupRightNavItems () {
let spacing = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
spacing.width = 25 //change to your desired space width
navigationItem.rightBarButtonItems = [submitBarButtonItem, spacing, previewBarButtonItem]
}