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

Lau*_*a M 5 xcode ios swift

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

J.W*_*ang 7

试试这个:

    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)
Run Code Online (Sandbox Code Playgroud)