I'm trying to subclass an NSButton/NSButtonCell so I can get some custom drawing. Really, the only thing I want to do is make the text a different color (say, red).
My buttons are all now "ColoredButton"s, and I've created an NSButtonCell class.
I've tried two approaches to setting the cell class for my ColoredButtons - and both of them have problems. 1) in the +initialize method, I've added:
[self setCellClass:[ColoredButtonCell class]]; Also, I added: + (Class) cellClass { return [ColoredButtonCell class]; }
Now, this approach seems to do nothing for cells I create in IB. It seems that other people on this list have seen the same behavior. OK, I guess that's the way it is.
So, I tried
2) in ColoredButton's awakeFromNib: - (void) awakeFromNib { [[self class] setCellClass:[ColoredButtonCell class]]; ColoredButtonCell *cell = [[ColoredButtonCell alloc] init]; [self setCell:cell]; }
This sort of works, but has some nasty side effects. Namely, everything I've set up in IB for the NSButton seems to get lost. This includes the button type, the title (the title becomes "Button" for all of them!), and even the keyequivalents. So I end up with the red text buttons I want, but they all just say "button", and nothing works.
What fixes this? Or, is there an easier way to change the text color for an NSButton? (I also kind of want to override the cell color when the button is clicked).
|