I try to use a custom view for a NSMenuitem
, which works. Unfortunately, I have some difficulties with the highlighting (mouseover). I already followed the instructions in other threads to implement drawRect:
in my NSView
subclass to do the blue highlighting manually. This seems to work, but the highlighting color is not correct. It appears too dark compared to regular menu items and interestingly the subviews
of my custom view use the correct highlighting color (see screenshot).
Any ideas on how to fix this issue?
My current drawRect:
method in the NSView
subclass looks like this:
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
BOOL isHighlighted = [[self enclosingMenuItem] isHighlighted];
if (isHighlighted)
{
[[NSColor selectedMenuItemColor] setFill];
NSRectFill(dirtyRect);
[self.profileNameView setTextColor:[NSColor whiteColor]];
[self.securedIPView setTextColor:[NSColor whiteColor]];
[self.separatorView setTextColor:[NSColor whiteColor]];
[self.connectionTimeView setTextColor:[NSColor whiteColor]];
}
else
{
[self.profileNameView setTextColor:[NSColor controlTextColor]];
[self.securedIPView setTextColor:[NSColor disabledControlTextColor]];
[self.separatorView setTextColor:[NSColor disabledControlTextColor]];
[self.connectionTimeView setTextColor:[NSColor disabledControlTextColor]];
}
}
The resulting highlighting looks like: