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()
]

      

+3


source to share


2 answers


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.



+1


source


The answer is to set the color of the view layer NSColor.textColor()

in the viewDidAppear method. You also need the views to wantsLayer

be set to true

.



0


source







All Articles