Skip navigation.
 
mlRe: background of NSButton and NSPopUpButton
FROM : Michael Becker
DATE : Thu Nov 25 12:00:29 2004

Hi!

Am 25.11.2004 um 11:20 schrieb Don Willems:
> Now I'm thinking of subclassing NSButtonCell and NSPopUpButtonCell,
> but I'm not sure how to go about that.


Just subclass e.g. NSPopUpButton. This is itself an NSView-subclass, so
you can just override drawRect: like this:

- (void)drawRect:(NSRect)cellFrame {
   // Creating a red background
   [[ NSColor redColor] set];
   NSRectFill([self bounds]);
   
   [[ self cell] drawWithFrame:cellFrame inView:self];
}

The call to drawWithFrame:inView: will draw the PopUpButton. If you
want it to look like in the "bar" in Xcode, set the PopUpButton to be
not bordered.
Personally, though, I would go with your first idea (creating a
background view and placing non-bordered buttons on it) because this
way you can be sure that there are no graphical differences between
your button's background and the rest.

Cheers,
Michael

Related mailsAuthorDate
mlbackground of NSButton and NSPopUpButton Don Willems Nov 25, 11:20
mlRe: background of NSButton and NSPopUpButton Michael Becker Nov 25, 12:00
mlRe: background of NSButton and NSPopUpButton Don Willems Nov 25, 13:32
mlRe: background of NSButton and NSPopUpButton Michael Becker Nov 25, 15:25
mlRe: background of NSButton and NSPopUpButton Don Willems Nov 25, 22:11
mlRe: background of NSButton and NSPopUpButton Ryan Stevens Nov 25, 23:47
mlRe: background of NSButton and NSPopUpButton Don Willems Nov 26, 09:15
mlRe: background of NSButton and NSPopUpButton Don Willems Nov 26, 09:22