本文介绍了如何检查是否启用了深色外观 tvOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查用户是否在其 Apple TV 上启用了深色外观?
解决方案
使用
<string>自动</string>
How do I check if a user has enabled Dark Appearance on their Apple TV?
解决方案
Using UIUserInterfaceStyle, first available in tvOS 10, we can check what appearance the user has set.
For example:
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")
}
}
Also, if you're updating from an Xcode 7/tvOS 9.0 project you will need to include UIUserInterfaceStyle
in your info.plist
. New projects created with Xcode 8 already have this key included.
<key>UIUserInterfaceStyle</key>
<string>Automatic</string>
这篇关于如何检查是否启用了深色外观 tvOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!