2016-09-18 31 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

我試過了,還是**未指定**。 –