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: Peter Teeson <email@hidden>
- Date: Thu, 26 Dec 2013 22:08:13 -0500
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.
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.
respect…
Peter
_______________________________________________
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