工具栏不能使按钮垂直居中

问题描述

有人可以向我解释为什么以编程方式将按钮添加到工具栏时Xcode不能使按钮垂直居中吗?当我处理使用情节提要添加的工具栏时,该按钮在水平和垂直居中显示。

通过情节提要添加的工具栏(看起来很完美):

enter image description here

通过代码添加的工具栏:

enter image description here

我的代码:

self.navigationController?.isToolbarHidden = false
let testButton = UIButton(type: .custom)
testButton.setTitle("Test",for: .normal)
testButton.addTarget(self,action: #selector(test),for: .touchUpInside)
testButton.backgroundColor = .black
testButton.setTitleColor(.white,for: .normal)
testButton.titleLabel?.font = .boldSystemFont(ofSize: 17)
let tb = UIBarButtonItem(customView: testButton)
self.toolbarItems = [tb]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)