【问题标题】:how can I set the tint color of right UIBarButtonItem in Swift?如何在 Swift 中设置右 UIBarButtonItem 的色调颜色?
【发布时间】:2017-06-07 11:23:56
【问题描述】:

我正在使用viewDidLoad 中的以下代码向我的导航控制器添加一个右栏按钮:

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

    self.navigationItem.rightBarButtonItem = b

我的settings png 文件是白色的,但是当我运行应用程序时,我看到它是默认的blue 颜色。不管怎样,我想把它改成红色。我该怎么做?

我试过了:

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

但它没有用。这样做的正确方法是什么?

【问题讨论】:

    标签: ios swift uinavigationcontroller uibarbuttonitem uibarbuttonitemstyle


    【解决方案1】:

    你试过了吗:

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

    编辑:

    我实际上使用以下内容:

    navigationController.navigationBar.barTintColor = UIColor.red
    

    【讨论】:

    • @user3766930 对不起,我打错了,检查我编辑的帖子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多