2

My OS is set to dark mode, and my whole app renders properly, except for some dynamically created NSMenu instances, which render in the old light style.

How do I get those menus to render using a dark visual style?

CuriousGeorge
  • 7,120
  • 6
  • 42
  • 74

2 Answers2

2

The dark visual style is only applied if you specify the parent view.

If view is nil here, the old style will be used instead:

NSMenu* menu;
NSView* view; // cannot be nil
[menu popUpMenuPositioningItem:nil atLocation:NSMakePoint(0, 0) inView:view];
CuriousGeorge
  • 7,120
  • 6
  • 42
  • 74
0

There is an undocumented apperance argument for popUpMenuPositioningItem. You have to customize the existing NSMenu class to use it:

@interface NSMenu ()
- (BOOL)popUpMenuPositioningItem:(nullable NSMenuItem *)item atLocation:(NSPoint)location inView:(nullable NSView *)view appearance:(nullable NSAppearance *)appearance NS_AVAILABLE_MAC(10_6);
@end

If you want to use it in Swift via popUp you have to declare it in an "Objective-C Bridging Header" file and add the path to the Xcode project's build settings under "Swift Compiler - General"

I found this solution here and here. Class extension is documented here.

bjunix
  • 4,458
  • 4
  • 33
  • 33