Re: Coloring NSButtonCells
Re: Coloring NSButtonCells
- Subject: Re: Coloring NSButtonCells
- From: Steve Gehrman <email@hidden>
- Date: Wed, 15 Aug 2001 23:39:58 -0700
Here's a simple subclass that changes the button when in the OnState. A
slight modification will get you what you want.
steve
#import "SelectableButtonCell.h"
#import "GlobalPreferences.h"
@interface SelectableButtonCell : NSButtonCell
{
}
@end
@implementation SelectableButtonCell
- (id)init
{
NSFont* font;
self = [super init];
// make it a smaller font
font = [self font];
font = [[NSFontManager sharedFontManager] convertFont:font
toSize:10];
[self setFont:font];
return self;
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView
*)controlView;
{
if ([self state] == NSOnState)
{
NSRect inset = NSInsetRect(cellFrame, 1, 1);
NSColor* hcolor = [[GlobalPreferences sharedInstance]
highlightColor];
if (hcolor == nil)
hcolor = [NSColor colorWithCalibratedRed:0.5 green:0.6
blue:0.9 alpha:0.4];
[hcolor set];
NSRectFillUsingOperation(inset, NSCompositeSourceAtop);
}
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
[super drawWithFrame:cellFrame inView:controlView];
}
- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView
*)controlView;
{
[super highlight:flag withFrame:cellFrame inView:controlView];
}
@end
On Wednesday, August 15, 2001, at 09:40 PM, cocoa-dev-
email@hidden wrote:
Newbie question here. Is it possible to give NSButtonCells a color?
For a
project I'm working on, I have an NSMatrix filled with NSButtonCells and
want to make it so that some of the buttons are different colors
depending
on variables. Looking through the api, nothings jumping out at me. I
was
thinking it maybe the setControlTint, but its got the always annoying
"description forthcoming."
--
Steve Gehrman
CocoaTech, Inc.
mailto:email@hidden
http://www.cocoatech.com