我正在尝试使用自定义视图(UIBarButtonItem
)添加6 UIButton
,并且我希望每个按钮在填充工具栏时填充高度并与其他按钮的宽度相同。使用以下代码,我接近了,但是在工具栏的开头和结尾处有一个空格。我究竟做错了什么?移除第一个和最后一个间隔物使得开始和结束处的空间更大,并且移除所有间隔物在每个间隔物之间存在巨大间隙UIBarButtonItem
override func viewDidLoad() {
let spacer = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil)
let b1 = UIBarButtonItem(customView: one)
let b2 = UIBarButtonItem(customView: two)
let b3 = UIBarButtonItem(customView: three)
let b4 = UIBarButtonItem(customView: four)
let b5 = UIBarButtonItem(customView: five)
let b6 = UIBarButtonItem(customView: six)
toolbarButtons = [spacer, b1, spacer, b2, spacer, b3, spacer, b4, spacer, b5, spacer, b6, spacer]
setToolbarItems(toolbarButtons, animated: false)
}
private func createBottomButton(number: String) -> UIButton {
let bottomButton = UIButton(type: UIButtonType.Custom)
bottomButton.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width / 6, height: 44)
bottomButton.setTitle(number, forState: UIControlState.Normal)
return bottomButton
}