如何检测 OS X 是否处于黑暗模式? [英] How to detect if OS X is in dark mode?

查看:24
本文介绍了如何检测 OS X 是否处于黑暗模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的可可应用程序在新的 OS X暗模式"下运行时必须改变其行为.

My cocoa app has to change its behaviour when run in the new OS X "dark mode".

有没有办法检测 OS X 样式是否设置为这种模式?

Is there a way to detect if OS X style is set to this mode?

推荐答案

不认为有可可检测它的方式,但是你可以使用 defaults read 来检查 OSX 是否是在黑暗模式下.

Don't think there's a cocoa way of detecting it yet, however you can use defaults read to check whether or not OSX is in dark mode.

defaults read -g AppleInterfaceStyle

要么返回Dark(黑暗模式),要么返回域对不存在.

Either returns Dark (dark mode) or returns domain pair does not exist.

正如 Ken Thomases 所说,您可以通过 NSUserDefaults 访问 .GlobalPreferences,所以

As Ken Thomases said you can access .GlobalPreferences via NSUserDefaults, so

NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];

如果 osxMode 是 nil 那么它不是处于黑暗模式,但如果 osxMode 是 @"Dark" 那么它处于黑暗模式.

If osxMode is nil then it isn't in dark mode, but if osxMode is @"Dark" then it is in dark mode.

这篇关于如何检测 OS X 是否处于黑暗模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆