Re: How to disable/gray an NSTextfield (used as static text)
Re: How to disable/gray an NSTextfield (used as static text)
- Subject: Re: How to disable/gray an NSTextfield (used as static text)
- From: Dietmar Planitzer <email@hidden>
- Date: Mon, 22 Nov 2004 10:54:36 +0100
On Nov 22, 2004, at 6:43 AM, Sean McBride wrote:
Daniel Todd Currie (email@hidden) on Sat, Oct 23, 2004 10:27 PM said:
I am using an NSTextField as a text label (ie not editable nor
selectable). I'd like to 'disable' this textfield so that it appears
gray instead of black.
If you really wanted to, I suppose you could subclass NSTextField and
make it so that text labels gray when they receive the -setEnabled:
message... Otherwise, this is just as good a way as any other:
[myTextLabel setTextColor:[NSColor disabledControlTextColor]];
A good idea, but incredibly apparently not so simple. :( I subclassed
like so:
- (void)setEnabled:(BOOL)flag
{
[super setEnabled:flag];
if (flag == NO) {
[self setTextColor:[NSColor disabledControlTextColor]];
} else {
[self setTextColor:[NSColor controlTextColor]];
}
}
But when I setEnabled:0, the colour changes, but not to the correct
colour!
I've put a very simple sample app here:
<http://www.cam.org/~cwatson/GreyingTextTest.sitx> (16 KB)
This seems too simple for me to be messing up, but I'd be happy to be
proven wrong. :)
Replace +disabledControlTextColor with +secondarySelectedControlColor
and you'll get the right color.
The easiest way to find out which NSColor factory selector corresponds
to which color is to check out the Developer color palette in the color
panel. For example, open TextEdit and bring up the color panel. Click
on the third button from the left in the toolbar (Color Palettes) and
select "Developer" from the List pop-up menu. The table below the menu
now shows a sample of each color on the left side and the corresponding
NSColor selector, that will produce this color, to the right of it.
Regards,
Dietmar Planitzer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden