How can I determine the macOS 10.14 accent color?

一笑奈何 提交于 2019-12-07 12:48:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!