如何更改 Swift 中的 backBarButtonItem 颜色?
How can I change the backBarButtonItem colour in Swift?
我正在尝试将默认的 backBarButtonItem 颜色更改为白色,
我的代码如下所示
self.navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但它对我不起作用,有什么想法吗?
试试这个:
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
试试这个:
self.navigationController?.navigationItem.backBarButtonItem?.tintColor = UIColor.red
如果您想更改 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
查看结果:
我正在尝试将默认的 backBarButtonItem 颜色更改为白色,
我的代码如下所示
self.navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但它对我不起作用,有什么想法吗?
试试这个:
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
试试这个:
self.navigationController?.navigationItem.backBarButtonItem?.tintColor = UIColor.red
如果您想更改 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
查看结果: