Re: NSButton, Templates, images…
Re: NSButton, Templates, images…
- Subject: Re: NSButton, Templates, images…
- From: Lee Ann Rucker <email@hidden>
- Date: Tue, 24 Jun 2014 15:59:25 -0700
According to rdar://9643033, which I filed 3 years ago, the bezelStyle has to be NSTexturedRoundedBezelStyle, and it'll work in 10.6 if bordered is NO, but 10.7 needs a border. I don't know if the bordered part is still required; I came up with a workaround to get just the image in the style I need- create a button cell like so:
NSButtonCell *buttonCell =
[[[NSButtonCell alloc] initImageCell:template] autorelease];
[buttonCell setBordered:YES];
[buttonCell setBezelStyle:NSTexturedRoundedBezelStyle];
[buttonCell setButtonType:NSToggleButton];
[buttonCell setShowsStateBy:NSContentsCellMask];
[buttonCell setHighlightsBy:NSCellLightsByContents];
and then set up a graphics context and call the button cell's drawImage method to get just the image I want.
I also asked for a way to generate the 3 different template effects in code; mine was closed as a dup of still-open rdar://8067825
On Jun 24, 2014, at 3:31 PM, Alex Kac wrote:
> I’m sure I’m missing something simple. Reading the docs, reading some stack-overflow comments, and a few posts on this list from years ago, it seems like I am missing something.
>
> I have an NSButton with an image. I’d like to have the button look etched when unselected - and tinted blue when selected just like the Xcode mini-tabbar here:
> https://urldefense.proofpoint.com/v1/url?u=https://www.dropbox.com/s/b1f9kxe5ww25ep7/Screenshot%202014-06-24%2016.24.55.png&k=oIvRg1+dGAgOoM1BIlLLqw==
&r=yJFJhaNnTZDfFSSz1U9TSNMmxGyib3KjZGuKfIhHLxA=
&m=sxUWtCjh+4ewI1f+oeXy/Ok2WBpiUPxoSsyDWjezd6g=
&s=3173ad0288269cdbf9973105ed8562ea7174d259743d1fea1e4f7ac03804c2bb
>
> I’m doing this in code, not in IB. I’m using an NSButton subclass:
> [self setButtonType: NSToggleButton];
> [self setBordered: NO];
> [self setTitle: @""];
> [self.cell setImageScaling: NSImageScaleProportionallyDown];
> self.bezelStyle = NSShadowlessSquareBezelStyle;
> self.focusRingType = NSFocusRingTypeNone;
>
>
> And on the image, we’re setting the setTemplate:YES property on it.
> [iconImage setTemplate:YES];
>
> According to several posts on this list, a bezel-less NSButton that’s a toggle button, should give me what I’m looking for, but its not. The obvious other option is to just create an alternate image…which I’m not against, but it just seems like it would be better to use a built-in system if one exists - or does one?
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden