2016-09-18 34 views

回答

8

使用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项目更新,你将需要包括UIUserInterfaceStyleinfo.plist。使用Xcode 8创建的新项目已经包含了此密钥。

enter image description here

<key>UIUserInterfaceStyle</key> 
    <string>Automatic</string> 
+0

我想这个编码 'didFinishLaunchingWithOptions',但它总是显示 '未指定'。 –

+0

@Anas可能为时尚早。尝试将它移动到你的第一个VC的'viewDidLoad'中。确保你的密钥也包含在你的info.plist中。 –

+0

我试过了,还是**未指定**。 –