如何在 Swift 中设置右侧 UIBarButtonItem 的色调颜色? [英] how can I set the tint color of right UIBarButtonItem in Swift?
本文介绍了如何在 Swift 中设置右侧 UIBarButtonItem 的色调颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 viewDidLoad
中的以下代码向我的导航控制器添加一个右栏按钮:
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
我的 settings
png 文件是白色的,但是当我运行应用程序时,我看到它是默认的 blue
颜色.不管怎样,我想把它改成红色.我该怎么做?
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?
我试过了:
let navigationBarAppearnce = UINavigationBar.appearance()
navigationBarAppearnce.tintColor = UIColor.red
但是没有用.这样做的正确方法是什么?
but it didn't work. What's the proper way of doing that?
推荐答案
您是否尝试过:
let navigationController = UINavigationController() //not how you should actually get it, but just for purpose of example
navigationController.navigationBar.tintColor = UIColor.red
我实际上使用以下内容:
I actually use the following:
navigationController.navigationBar.barTintColor = UIColor.red
这篇关于如何在 Swift 中设置右侧 UIBarButtonItem 的色调颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文