1

我正在尝试在按钮之间的导航栏 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]
}

你能提示一下为什么这不起作用吗?

谢谢

4

1 回答 1

1

我设法解决了这个问题,只是在条形按钮项目之间添加了一个固定空间,如下所示:

1)删除任何EdgeInsets 2)添加以下固定空间:

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]
}
于 2017-05-14T18:49:55.127 回答