2

A regular NSButton seems to be transparent if it’s disabled.

enter image description here

Image shows a Button with style 'push'

However, I want to disable the Button without the transparency.

I’ve tried to programmatically set the alphaValue to 1.0 but it seems that the NSButtons cell (controlView) as well as all other subviews are already at an alphaValue of 1.0.

Also, there’s nothing like userInteractionEnabled or adjustsImageWhenDisabled (both recommended here) I could use like in iOS.

How can I disable a NSButton without the standard transparency?

EDIT: Also a 'textured push' button appears to be transparent: enter image description here

Community
  • 1
  • 1
ixany
  • 5,433
  • 9
  • 41
  • 65
  • Do you have to use a regular push button? A textured rounded button doesn't have this issue. – rocky Feb 09 '17 at 08:10
  • @rocky See my updated question above: It seems that the 'textured push' button have a little less transparency, but it’s also transparent. – ixany Feb 09 '17 at 08:25
  • Ahh you're right. I guess I wasn't looking hard enough. Sorry about that. – rocky Feb 09 '17 at 08:29

1 Answers1

0

If you don't need the title, and will provide your own button image, you can use setImageDimsWhenDisabled to disable transparency in NSButtonCell's image when it is disabled. Here is the code:

[buttonCell setImageDimsWhenDisabled:NO];

NSButtonCell is the subview of NSButton. But as I said, the title will still be "dimmed" a little bit, and also its background. But since image if on top of the background, you won't see the transparent background.

Another way (avoid subclass NSButton) is to have your own state tracking variable for button. When the state is disabled, dismiss any click event. Sample framework of code is like this:

- (IBAction)clickOnButton {
    static BOOL isEnabled = YES;
    if (isEnabled) {
        // Handle click event here...

    }
    isEnabled = !isEnabled;
}

This may show the highlight when clicked. You can disable highlight also. But this is not a good idea if you have many buttons. If you have many buttons, subclass NSButton is the best choice.

Zhigang An
  • 296
  • 2
  • 13