答案 0 :(得分:4)
在按钮左侧和右侧添加一个灵活空间,使工具栏内的按钮居中。感谢Midhun MP提示。
答案 1 :(得分:0)
@Andrew认为有效 但是对于想要从代码中获取代码的人来说,这是Swift 5.0中的示例
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.setToolbarHidden(false, animated: true)
let spaceItemLeft = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
let nextItem = UIBarButtonItem(title: "NEXT", style: .plain, target: self, action: #selector(nextTapped))
let spaceItemRight = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
toolbarItems = [spaceItemLeft, nextItem, spaceItemRight]
}
@objc func nextTapped() {
print("NEXT Tapped")
}