iOS 11 中的 UIBarButtonItem 间距问题
UIBarButtonItems Spacing Issue in iOS 11
我正在尝试调整 UIBar 按钮项之间的间距。
func addLeftBarButtonItems() {
let btn1 = UIButton(type: UIButton.ButtonType.custom) as UIButton
let list_icon = UIImage(named: "list") as UIImage?
btn1.setImage(list_icon, for: UIControl.State.normal)
let item1 = UIBarButtonItem()
item1.customView = btn1
let btn2 = UIButton()
btn2.setTitle("Notification", for: .normal)
btn2.setTitleColor(UIColor.black, for: .normal)
let item2 = UIBarButtonItem()
item2.customView = btn2
let btn3 = UIButton(type: UIButton.ButtonType.custom) as UIButton
let redbadge = UIImage(named: "red_badge") as UIImage?
btn3.setBackgroundImage(redbadge, for: UIControl.State.normal)
btn3.setTitle("10", for: .normal)
btn3.titleLabel?.font = .systemFont(ofSize:10)
btn3.setTitleColor(UIColor.black, for: .normal)
let item3 = UIBarButtonItem()
item3.customView = btn3
let space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
space.width = -8
self.navigationItem.leftBarButtonItems = [ item1, item2 , space ,item3]
}
如何 reduce/increase 通知标题和徽章图标之间的差距以及 .固定的 space 似乎不起作用。
间距的负值不起作用。但是正值可以。
我正在尝试调整 UIBar 按钮项之间的间距。
func addLeftBarButtonItems() {
let btn1 = UIButton(type: UIButton.ButtonType.custom) as UIButton
let list_icon = UIImage(named: "list") as UIImage?
btn1.setImage(list_icon, for: UIControl.State.normal)
let item1 = UIBarButtonItem()
item1.customView = btn1
let btn2 = UIButton()
btn2.setTitle("Notification", for: .normal)
btn2.setTitleColor(UIColor.black, for: .normal)
let item2 = UIBarButtonItem()
item2.customView = btn2
let btn3 = UIButton(type: UIButton.ButtonType.custom) as UIButton
let redbadge = UIImage(named: "red_badge") as UIImage?
btn3.setBackgroundImage(redbadge, for: UIControl.State.normal)
btn3.setTitle("10", for: .normal)
btn3.titleLabel?.font = .systemFont(ofSize:10)
btn3.setTitleColor(UIColor.black, for: .normal)
let item3 = UIBarButtonItem()
item3.customView = btn3
let space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
space.width = -8
self.navigationItem.leftBarButtonItems = [ item1, item2 , space ,item3]
}
如何 reduce/increase 通知标题和徽章图标之间的差距以及 .固定的 space 似乎不起作用。
间距的负值不起作用。但是正值可以。