I wrote my own NSMenu like class to show dynamic search results below a NSSearchField
in a borderless NSWindow. It's working well but doesn't draw the magic selectedMenuItemColor
correctly if I add some padding to the top of the subview. I put a 5 pixel padding at the top of container view to mimic NSMenu and when I do it blue selected gradient looks off. A picture & code should make this clear:
Here is my drawRect code inside my item view (remember this is just a regular NSView):
-(void) drawRect:(NSRect)dirtyRect {
CGRect b = self.bounds;
if (selected) {
[NSGraphicsContext saveGraphicsState];
[[NSColor selectedMenuItemColor] set];
NSRectFill( b );
[NSGraphicsContext restoreGraphicsState];
if (textField) {
textField.textColor = [NSColor selectedMenuItemTextColor];
}
} else {
[[NSColor clearColor] set];
NSRectFillUsingOperation(b, NSCompositeSourceOver);
if (textField) {
textField.textColor = [NSColor blackColor];
}
}
}
selectedMenuItemColor
, I only get the dark blue background and not the lighter gradient on top of it as is shown in your screenshot. Did you have to do anything special to get that to show up? – jtbandes