macOS Hight Sierra / Mojave:以编程方式获取“系统偏好设置->可访问性->显示->增加对比度”的值

时间:2018-08-09 19:35:13

标签: macos-high-sierra macos-mojave

如何以编程方式在macOS Hight Sierra上获得提高对比度设置的值?了解如何观察这种价值变化也很有趣。

系统偏好设置的完整路径是系统偏好设置->辅助功能->显示->增加对比度

enter image description here

在macOS Mojave上,可以通过如下所示的effectiveAppearance.bestMatch API调用来实现。

open override func layout() {
  super.layout()
  if #available(OSX 10.14, *) {
     if let value = effectiveAppearance.bestMatch(from: [.aqua, .darkAqua, .accessibilityHighContrastAqua, .accessibilityHighContrastDarkAqua]) {

        switch value {
        case .aqua:
           setupAppearance(.light)
        case .darkAqua:
           setupAppearance(.dark)
        case .accessibilityHighContrastAqua:
           setupAppearance(.highContrastLight)
        case .accessibilityHighContrastDarkAqua:
           setupAppearance(.highContrastDark)
        default:
           break
        }

     }
  }
}

1 个答案:

答案 0 :(得分:1)