3

I have created an NSButton that uses an image only and no text. I create the button using the following code. The code is called from the containing window's awakeFromNib.

[[self contentView] addSubview:closeButton];
[[closeButton cell] setImageDimsWhenDisabled:YES];
[closeButton setBezelStyle:NSRoundedBezelStyle];
[closeButton setButtonType:NSMomentaryChangeButton];
[closeButton setBordered:NO];
[closeButton setImage:[NSImage imageNamed:@"title-close"]];
[closeButton setAlternateImage:[NSImage imageNamed:@"title-close-alt"]];
[closeButton setTitle:@""];
[closeButton setImagePosition:NSImageOnly];
[closeButton setFocusRingType:NSFocusRingTypeNone];
[closeButton setTarget:self];
[closeButton setAction:@selector(performClose:)];
[closeButton setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
if(!_hasCloseWindowButton)
[closeButton setEnabled:NO];

If I don't make the call to [closeButton setEnabled:NO] the button is drawn and works perfectly. Button Enabled

If [closeButton setEnabled:NO] is called, the button is either hidden or not being drawn. Button Disabled

Is there some way to specify an image for the disabled state that I am somehow missing in the docs ?

Does anyone have a clue what I might be doing wrong?

Brad S
  • 585
  • 3
  • 12
  • So what does your disabled image look like? You can specify something like 4 different images for a button. – Hot Licks Dec 07 '13 at 02:12
  • (OK, for NSButton only two images -- normal and alternate.) – Hot Licks Dec 07 '13 at 02:16
  • I'd subclass `NSButton` to add the behavior. do you really want another image tho? from the look of your sample you really want an effect, not another image. – Brad Allred Dec 07 '13 at 04:05
  • There is the normal image which you see above and an alternate image which is just a lighter version on the normal image. I was hoping the call to setImageDimsWhenDisabled: on the button cell would get me a darker version of my normal image. – Brad S Dec 07 '13 at 04:11

0 Answers0