0
votes

I have a NSTextField which is enabled or disabled. I can set the textColor but this only has an effect on the color of the text while the text field is enabled.

Any ideas how to set the text color for the disabled state?

I already tried to subclass NSTextField and override the enable methods as suggested in Disable NSTextField without changing color of multi-colored text ... but that doesn't work for me. I guess because of the latest SDK supporting dark mode.

1

1 Answers

0
votes

Simple approach is to override resignFirstResponder:

override func resignFirstResponder() -> Bool {
    //change text color here...

    return super.resignFirstResponder()
}

You can simply add your colour change code for whichever controls you like here...

As stated by Apple: The default implementation returns true, resigning first responder status. You can override this method in your custom responders to update your object's state or perform other actions, such as removing the highlight from a selection. You can also return false, refusing to relinquish first responder status. If you override this method, you must call super (the superclass implementation) at some point in your code.