title: Trouble matching the vibrant background of a Yosemite NSMenuItem containing a custom view
body: <p>I am attempting to add a custom view to an NSMenuItem in the OS X 10.10 Yosemite menu bar.</p>
  
  <p>The custom view is simply an NSView background with an NSTextField “label”.</p>
  
  <p>The problem is that the background NSView is given Yosemite-style vibrancy/transparency when added to the menu. The NSTextfield label is not.</p>
  
  <p><img src="https://i.stack.imgur.com/Lp7Fa.png" alt="Background colors do not match"></p>
  
  <p>Through the use of <code>NSRectFillUsingOperation</code> I've gotten this to look good for <em>some</em> background colors in Yosemite. But others continue to not match. When it is working, after manually "highlighting" the view, the original colors change and no longer match. I can dig up some example code for this if needed.</p>
  
  <p>Then, when it is looking somewhat good in Yosemite, it looks terrible in 10.9 Mavericks.</p>
  
  <p>I've also tried setting the <code>wantsLayer</code> property to YES to turn the view into a CALayer-backed view. This creates other issues such as text not anti-aliasing correctly against a clear background. </p>
  
  <p>My Question:</p>
  
  <p>How do I display a label on top of a NSMenuItem custom view? The label's background must exactly match the view's background. Solution must work in Yosemite and Mavericks.</p>
  
  <p>Example code below:</p>
  
  <pre><code>self.statusItem = [[NSStatusBar systemStatusBar]
  statusItemWithLength:NSVariableStatusItemLength];
  [self.statusItem setTitle:@"TEST"];
  [self.statusItem setHighlightMode:YES];
  [self.statusItem setEnabled:YES];
  [self.statusItem setTarget:self];
  
  NSMenu *menu = [[NSMenu alloc] init];
  [menu addItemWithTitle:@"Disabled menu item" action:nil keyEquivalent:@""];
  [menu addItemWithTitle:@"Enabled menu item" action:@selector(enabled) keyEquivalent:@""];
  
  NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(30, 20, 50, 20)];
  label.stringValue = @"label";
  label.editable = NO;
  label.bordered = NO;
  label.backgroundColor = [NSColor blueColor];
  //label.backgroundColor = [NSColor clearColor];
  
  
  PKMenuItemView *view = [[PKMenuItemView alloc] initWithFrame:NSMakeRect(0, 0, 200, 50)];
  [view addSubview:label];
  
  NSMenuItem *viewMenuItem = [[NSMenuItem alloc] init];
  [viewMenuItem setView:view];
  [menu addItem:viewMenuItem];
  
  self.statusItem.menu = menu;
  </code></pre>
  
  <p>I've subclassed the NSView to override <code>drawRect:</code> and draw a colored background:  </p>
  
  <pre><code>- (void)drawRect:(NSRect)dirtyRect {
      [super drawRect:dirtyRect];
  
      [[NSColor blueColor] setFill];
      NSRectFill(dirtyRect);
      //NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
  }
  </code></pre>