在iOS中更改禁用栏按钮项的颜色

前端之家收集整理的这篇文章主要介绍了在iOS中更改禁用栏按钮项的颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在导航栏中显示我的应用程序图标.为此,我将其添加为右键按钮项.我不希望它是可点击的,我只需要那里的图标,所以我将它设置为禁用.这个问题是图标显示为灰色,而不是绿色.有没有办法禁用此按钮,但也保持原始颜色?

解决方法

试试这个:

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)

猜你在找的Xcode相关文章