Menu text color in dark mode in Cocoa
NSColor
has this method:
NSColor.selectedMenuItemTextColor()
But there is no way for a normal (unselected) menu item text color. How do I determine the color of the menu text (which is currently black for normal mode, white for "dark" mode)?
I have a custom view in my menu and it should use the same text color as the other menu items.
EDIT: I'm using this now, but I'm hoping to find a cleaner solution for textAttributes
:
let isDark = NSAppearance.currentAppearance().name.hasPrefix("NSAppearanceNameVibrantDark")
let textAttributes = [
NSForegroundColorAttributeName: isDark ? NSColor.whiteColor() : NSColor.textColor()
]
let selectedItemTextAttributes = [
NSForegroundColorAttributeName: NSColor.selectedMenuItemTextColor()
]
source to share
Help for NSColor and selectedMenuItemColor
links to: see Accessing System Colors in the Color Programs section. This chapter talks about opening developer colors in the default color selector. There you will also find labelColor
a couple more that are not listed in the default interface. Perhaps one of them is the one you are after.
source to share