One Quickie


Show NSTextField text in gray if the field is disabled (NSTextView->General)
NSTextField doesn't change its text color if the field is enabled or disabled (?) Even more bizarre, using NSColor's disabledControlTextColor won't draw the text in the disabled color. You need to use the secondarySelectedControlColor, which supposedly is for active controls that don't have focus. Go figure.

To do it yourself, subclass NSTextField and override setEnabled: to change the color:

- (void) setEnabled: (BOOL) flag
{
    [super setEnabled: flag];

    if (flag == NO) {
        [self setTextColor: [NSColor secondarySelectedControlColor]];
    } else {
        [self setTextColor: [NSColor controlTextColor]];
    }

} // setEnabled

This actually kind of a gross workaround for a Cocoa bug - the disabled color is getting made darker rather than lighter. The secondarySelectedControlColor ends up looking disabled by a happy coincidence that it starts out lighter before being darkened. (or something like this. UberDude Dave MacLachlan has done the legwork to figure out the underlying problem.)



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com