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?
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?
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];
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.