我目前正在开发一个项目,该项目需要像这样的底部的工具栏:
我做了这样的事情:
@IBOutlet weak var doneBtn: UIButton!
@IBOutlet weak var bookmarkBtn: UIButton!
@IBOutlet weak var paddingLeft: UIBarButtonItem!
@IBOutlet weak var paddingRight: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
if UIDevice.current.model.hasPrefix("iPad") {
paddingLeft.width = -12
//paddingRight.width = -12
} else {
paddingLeft.width = -20
//paddingRight.width = -20
}
}
override func viewDidLayoutSubviews() {
setupToolbar()
print(self.view.bounds.size)
}
func setupToolbar() {
self.navigationController?.toolbar.frame.size.width = self.view.bounds.size.width
let doneBtnHeight = self.navigationController?.toolbar.bounds.size.height
let doneBtnWidth = (self.navigationController?.toolbar.frame.size.width)! - bookmarkBtn.frame.size.width
doneBtn.frame = CGRect(x: 0, y: 0, width: doneBtnWidth, height: doneBtnHeight!)
}
您会看到右侧有很多间距,并且按钮的宽度不正确。 (在iPad上效果很好,但在iPhone上效果不佳)有人可以启发我吗?