本文介绍了如何在 Swift 中更改 backBarButtonItem 颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将默认的 backBarButtonItem 颜色更改为白色,
我的代码如下
self.navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但这对我不起作用,有什么想法吗?
解决方案
如果你想改变 backBarButton 这样做:
override func viewDidLoad() {super.viewDidLoad()让 newBackButton = UIBarButtonItem(title: "B",样式:UIBarButtonItem.Style.plain,目标:自我,动作:backAction")navigationController?.navigationBar.topItem?.backBarButtonItem = newBackButtonnewBackButton.tintColor = .red//加载视图后进行任何其他设置.}func backAction() ->空白 {self.navigationController?.popViewController(动画:真)}
I am trying to change the default backBarButtonItem colour to white colour,
my codes look like below
self.navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
But It is not working for me, any ideas?
解决方案
If you want to change the backBarButton do this :
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)
}
See the result:
这篇关于如何在 Swift 中更改 backBarButtonItem 颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!