Dan*_*orm 14
使用首先在tvOS 10中提供的UIUserInterfaceStyle,我们可以检查用户设置的外观.
例如:
func checkInterfaceStyle() {
guard(traitCollection.responds(to: #selector(getter: UITraitCollection.userInterfaceStyle)))
else { return }
let style = traitCollection.userInterfaceStyle
switch style {
case .light:
print("light")
case .dark:
print("dark")
case .unspecified:
print("unspecified")
}
}
Run Code Online (Sandbox Code Playgroud)
此外,如果您从Xcode 7/tvOS 9.0项目更新,则需要包含UIUserInterfaceStyle在您的info.plist.使用Xcode 8创建的新项目已包含此密钥.
<key>UIUserInterfaceStyle</key>
<string>Automatic</string>
Run Code Online (Sandbox Code Playgroud)