Re: Creating NSButton in Code does not set controlTint to currentControlTint
Re: Creating NSButton in Code does not set controlTint to currentControlTint
- Subject: Re: Creating NSButton in Code does not set controlTint to currentControlTint
- From: Uli Kusterer <email@hidden>
- Date: Sat, 28 Dec 2013 14:39:48 +0100
On 27 Dec 2013, at 04:08, Peter Teeson <email@hidden> wrote:
> On 2013-12-26, at 7:01 PM, Uli Kusterer <email@hidden> wrote:
>> On 26 Dec 2013, at 18:49, Peter Teeson <email@hidden> wrote:
>>> _Cancel = [[NSButton alloc]init];
>>> [_Cancel setFrame:theButtonFrame];
>>> [_Cancel setNeedsDisplay:YES];
>>
>> Several issues here:
>>
>> 1) Control tints only apply to window widgets, focus borders, token capsules and to Aqua UI. MacOS X 10.7 removed the last aqua buttons and replaced them with grey, tint-less buttons. So whatever tint you set, you won’t see it anymore these days. Those grey, tint-less buttons look very similar to some other button types these days.
>>
>> 2) When you create a new NSButton, it is by default set up to look like a NeXT-style button. You need to set its bezel to NSRoundedBezelStyle to get a Mac-style button. NeXT-style buttons don’t honour the tint either. So the code you posted isnot identical to the button you create in IB. Hence, even if you’re running on 10.6 or earlier where buttons still show the tint, it’s not surprising that your button looks different.
>>
>> 3) As others mentioned, buttons are usually set to “default”. To find out what that corresponds to, look at NSColor’s currentControlTint method.
> Thanks for your comments Uli. The docn in Color Programming Topics Using the System Control Tint says this:
>
> OS X allows a user to set the color used in the display of windows, menus and controls using the Appearance pane in System Preferences. This color is referred to as the control tint. User interface elements provided by the Application Kit automatically modify their appearance based on the current control tint.
>
> I understand this to mean that NSButton, which inherits directly from NSControl, and which is a user interface element in the App Kit, should be using the Aqua tint as default assuming it's set to Blue in the System preferences.
Nope. The tint is a special feature of some button types. It is not something that all button bezels do. E.g. NSShadowlessSquareBezelStyle *never* (at least not since the introduction of Aqua in 10.0 — it might have been different in Mac OS X Server 1.0 which still had the OS 9 “Platinum” appearance) drew using the tint.
The only things in 10.0 that used the tint were Rounded (highlight/default buttons) and Circle bezel buttons (only to highlight), menu selections, tab controls, popup buttons, segmented controls, progress bars and scroll bars. Also the apple in the menu bar. Furthermore, window widgets were colored (red, yellow, green) with the blue tint, but had the same graphite tint under graphite.
> My code which you referred to was merely to show that I had tried, based to the Designated Initializers value statement, to use the default init. To try and make clear what my code is without the debug here it is again (theButtonFrame has been calculated prior to this code):
> _Cancel= [[NSButton alloc]initWithFrame:theButtonFrame];
> [_Cancel setTitle:@"Cancel"];
> [_Cancel setButtonType:NSToggleButton];
> [_Cancel setState:NSOffState];
> [_Cancel setBordered:YES];
> [_Cancel setBezelStyle:NSShadowlessSquareBezelStyle];
> [_Cancel.cell setControlTint:NSBlueControlTint];
> [theContentView addSubview:_Cancel];
>
> To repeat… I expected the above code to produce a button which when pressed displays the Blue Aqua tint. It doesn't! Why not?
> Why does it show the Aqua tint if I set up the exact same button using IB and let it be instantiated from the nib?
> Because that's where I got the information for the above set… statements. In my naiveté I assumed I would get the same behaviour.
What are you trying to achieve with all this? What do you mean by “display the blue aqua tint”? I think you’re misunderstanding the terminology. The tint is a color that is used for accents on *some* controls to make important parts stand out more, and to show whether a button is clickable even when its window is inactive. On pushbuttons, the tint was ever only used for the default button (the one that reacts to the return key) and for click-highlighting a button. The OS does that correctly and automatically, there is no reason for you to change this. The tint is *not* a way to theme a button or give it a particular color.
Also, Apple has reduced the number of places where this tint is still used with redesigns of the window titles, scrollbar and button shapes. So you rarely see the tint anymore.
Are you perhaps mixing up the control tint (which is conceptually like “a color accents are drawn in”) and the pulsing default button appearance (which is an unrelated feature that just uses this color)? In that case, you need to create a button of rounded bezel with the keyboard shortcut set to return (“\r").
Cheers,
-- Uli Kusterer
“The Witnesses of TeachText are everywhere...”
http://zathras.de
_______________________________________________
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