6

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:

enter image description here

Gürhan KODALAK
  • 570
  • 7
  • 20
Fabian Jäger
  • 447
  • 1
  • 5
  • 12
  • 1
    This does not help, because then there is no highlighting at all... – Fabian Jäger Jun 03 '15 at 11:55
  • 1
    The problem is related to the one described in http://stackoverflow.com/questions/26851306/trouble-matching-the-vibrant-background-of-a-yosemite-nsmenuitem-containing-a-cu Somehow the custom view does not correctly adapt to the menu's vibrant drawing in Yosemite. – Fabian Jäger Jun 03 '15 at 11:59
  • Please try this color [NSColor colorWithCalibratedRed:.0705 green:0.3755 blue:0.9529 alpha:1.0] – Sheen Vempeny Jun 07 '15 at 06:18
  • 4
    Hey @FabianJäger, I found that in the latest Shimo the highlight looks really good. Can you share what you’ve done? Thank you! – Xhacker Liu Oct 02 '15 at 02:25

0 Answers0