Re: NSButton, Templates, images…

2014-06-24 Thread Quincey Morris
On Jun 24, 2014, at 15:31 , Alex Kac  wrote:

> I’m sure I’m missing something simple.

> I have an NSButton with an image. I’d like to have the button look etched 
> when unselected - and tinted blue when selected

It was a while back since I was missing the same thing. IIRC, what you need to 
do is:

1. Set your template image as *both* the standard and the alternate image.

2. Set the button’s *value* to 1 to get the alternate image — which will then 
have the blue highlight.

Currently, I don’t have any buttons that do this with images, but I use the 
same rules for text that turns blue when the button is “on”. Previously, I used 
this for a “play” button that had a black play icon when off, and a blue pause 
icon when on. That ability to use different images for the states is why you 
have to set the image twice.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSButton, Templates, images…

2014-06-24 Thread Lee Ann Rucker
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%25202014-06-24%252016.24.55.png&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=yJFJhaNnTZDfFSSz1U9TSNMmxGyib3KjZGuKfIhHLxA%3D%0A&m=sxUWtCjh%2B4ewI1f%2BoeXy%2FOk2WBpiUPxoSsyDWjezd6g%3D%0A&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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://urldefense.proofpoint.com/v1/url?u=https://lists.apple.com/mailman/options/cocoa-dev/lrucker%2540vmware.com&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=yJFJhaNnTZDfFSSz1U9TSNMmxGyib3KjZGuKfIhHLxA%3D%0A&m=sxUWtCjh%2B4ewI1f%2BoeXy%2FOk2WBpiUPxoSsyDWjezd6g%3D%0A&s=fd77d59caaeb325d5592663d322cb491f3d1d051b38e1743accbfc462ca0ed4d
> 
> This email sent to lruc...@vmware.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

NSButton, Templates, images…

2014-06-24 Thread Alex Kac
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://www.dropbox.com/s/b1f9kxe5ww25ep7/Screenshot%202014-06-24%2016.24.55.png

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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com