how can I set the tint color of right UIBarButtonItem in Swift?

淺唱寂寞╮ 提交于 2019-12-12 01:46:13

问题


I'm adding a right bar button to my navigation controller with the following code in viewDidLoad:

var b = UIBarButtonItem(
        image: UIImage(named: "settings"),
        style: .plain,
        target: self,
        action: #selector(sayHello(sender:))
    )

    self.navigationItem.rightBarButtonItem = b

my settings png file is white, but when I run the app, I see it in default blue color. Anyway, I want to change it to red. How can I do it?

I tried this:

let navigationBarAppearnce = UINavigationBar.appearance()
navigationBarAppearnce.tintColor = UIColor.red

but it didn't work. What's the proper way of doing that?


回答1:


Have you tried:

let navigationController = UINavigationController() //not how you should actually get it, but just for purpose of example
navigationController.navigationBar.tintColor = UIColor.red

Edit:

I actually use the following:

navigationController.navigationBar.barTintColor = UIColor.red


来源:https://stackoverflow.com/questions/41798084/how-can-i-set-the-tint-color-of-right-uibarbuttonitem-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!