问题
MacOS 10.14 (Mojave) features a Dark interface style, and user selectable color accents. How to read these values and listen for changes?
回答1:
This is stored in the system defaults, available through NSDistributedNotificationCenter
.
Dark mode is active when AppleInterfaceStyle
is set to Dark
. Changes can be observed by listening for the InterfaceStyleChanged
notification.
The accent color can be read from AppleAccentColor
. Changes can be observed by listening for the AppleColorPreferencesChangedNotification
notification. Both returns an optional integer, that maps to:
nil: blue
-1: graphite
0: red
1: orange
2: yellow
3: green
5: purple
6: pink
回答2:
The accent color is available as NSColor.controlAccentColor
in macOS 10.14 or newer.
On NSView
level you can implement event handler viewDidChangeEffectiveAppearance()
to track accent color changes.
来源:https://stackoverflow.com/questions/51695755/how-can-i-determine-the-macos-10-14-accent-color