在iOS中更改禁用栏按钮项的颜色 [英] Change color of disabled bar button item in iOS

查看:186
本文介绍了在iOS中更改禁用栏按钮项的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在导航栏中显示我的应用程序图标。为此,我将其添加为右键按钮项。我不希望它是可点击的,我只需要那里的图标,所以我把它设置为禁用。这个问题是图标显示为灰色,而不是绿色。有没有办法禁用此按钮,但也保持原始颜色?

I need to display my app's icon in the navigation bar. To do this, I have added it as a right bar button item. I don't want it to be clickable, I just need the icon there, so I set it to disabled. The problem with this is the icon appears grey, instead of green. Is there a way to disable this button but also keep it's original color?

推荐答案

试试这个:

    let barButtonItem = UIBarButtonItem(title: "Click", style: .Done, target: self, action: #selector(didClick(_:)))

    barButtonItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blueColor()], forState: .Normal)
    barButtonItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blueColor()], forState: .Disabled)

    barButtonItem.enabled = false
    navigationItem.setRightBarButtonItem(barButtonItem, animated: false)

这篇关于在iOS中更改禁用栏按钮项的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆