For some reason, when my button is disabled, the text color turns white. I want it to stay black - how can i do that?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
You can subclass NSButtonCell and override a method:
In this way, when button is disabled, the text will have the same color of text when button is enabled.
Also check out this
Update for swift 4:
This will make text attributes the same as when button is enabled.
You can override a private method in NSButtonCell:
I filled a radar for a public method: rdar://19218619
You can set text, image, colors, fonts, etc. for different status of a button: normal, highlighted, disabled, etc.
You can do that in Interface Builder by changing the state with the dropdown list.
In Mojave, any override of draw methods makes it impossible to change the backgroundColor of the NSbutton when highlighted. So I would rather recommend to use
- (BOOL)_shouldDrawTextWithDisabledAppearance
for this purpose. If you are using Swift 4, I would do the following in the Bridging header:
And in the subclass of NSButtonCell: