【问题标题】:How can I change the backBarButtonItem colour in Swift?如何在 Swift 中更改 backBarButtonItem 颜色?
【发布时间】:2015-04-27 13:00:18
【问题描述】:
我正在尝试将默认的 backBarButtonItem 颜色更改为白色,
我的代码如下所示
self.navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但这对我不起作用,有什么想法吗?
【问题讨论】:
标签:
swift
uinavigationcontroller
uinavigationbar
uinavigationitem
backbarbuttonitem
【解决方案1】:
试试这个:
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
【解决方案2】:
如果你想改变 backBarButton 这样做:
override func viewDidLoad() {
super.viewDidLoad()
let newBackButton = UIBarButtonItem(title: "B",
style: UIBarButtonItem.Style.plain, target: self, action: "backAction")
navigationController?.navigationBar.topItem?.backBarButtonItem = newBackButton
newBackButton.tintColor = .red
// Do any additional setup after loading the view.
}
func backAction() -> Void {
self.navigationController?.popViewController(animated: true)
}
image of code
查看结果:
【解决方案3】:
试试这个:
self.navigationController?.navigationItem.backBarButtonItem?.tintColor = UIColor.red