2
如何檢查用戶是否在Apple TV上啓用了黑暗外觀?如何檢查是否啓用了黑暗外觀tvOS
如何檢查用戶是否在Apple TV上啓用了黑暗外觀?如何檢查是否啓用了黑暗外觀tvOS
使用UIUserInterfaceStyle,首先在tvOS 10中可用,我們可以檢查用戶設置了什麼外觀。
例如:
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")
}
}
此外,如果您是從Xcode中7/tvOS 9.0項目更新,你將需要包括UIUserInterfaceStyle
在info.plist
。使用Xcode 8創建的新項目已經包含了此密鑰。
<key>UIUserInterfaceStyle</key>
<string>Automatic</string>
我想這個編碼 'didFinishLaunchingWithOptions',但它總是顯示 '未指定'。 –
@Anas可能爲時尚早。嘗試將它移動到你的第一個VC的'viewDidLoad'中。確保你的密鑰也包含在你的info.plist中。 –
我試過了,還是**未指定**。 –