NSTextField text and background color with / without focus

I had a problem resetting colors when choosing NSTextField.
The methods that I use

- (void) setBackgroundColor:(NSColor *)aColor - (void) setTextColor:(NSColor *)aColor 

I found that when I clicked on NSTextField and thereby placed the focus in this text box, then I tried to change the color, the colors were not reset until the focus was placed outside this text box.
Color changing otherwise worked when the focus was not on the NSTextField, to start with.

+4
source share
1 answer

A simple solution that I found without access to the first responder was reset as editable / not editable after changing colors.

 - (void) setEditable:(BOOL)flag 

By setting the flag to NO and then YES in the next two calls (or YES and then NO depending on usage), this seems to remove focus from the NSTextField and then put it back and also update the colors.

Hope this helps.

+3
source

Source: https://habr.com/ru/post/1480166/


All Articles