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

Am 25.11.2004 um 13:32 schrieb Don Willems:

> I did both!
> I used a superview for the background image.
> And I had to create subclasses of NSButton and NSPopUpButton for the
> thin lines between the buttons (to separate them).
>
> I'm not completely satisfied with the result yet. It seems that the
> border-less NSPopUpButton draws the arrows right next to the far right
> of its frame, causing the separator line to be drawn in contact with
> the arrows. It needs some tweeking.


That is quickly done, just make the NSRect in which the cell is drawn
smaller:

- (void)drawRect:(NSRect)cellFrame {
   // Draw the line
   [[ NSColor blackColor] set];
   NSRect frame = [self bounds];
   NSFrameRect( NSMakeRect(frame.size.width-1, 0, 1, frame.size.height) );
   
   // Draw the button
   NSRect innerFrame = cellFrame;
   innerFrame.size.width -= 5;    
   [[ self cell] drawWithFrame:innerFrameFrame inView:self];
}

> The biggest problem now is highlighting, if I click a button, the
> button background becomes white, not aqua blue.


Okay, I am not sure how to go about this. You could subclass
NSButtonCell and play around with the -highlight:withFrame:inView:
method. But I think it will not be very trivial to implement the
typical aqua semi-transparent blue glow. Maybe you can work with
exchanging the background image by a highlighted one?

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