Rau*_*mar 3 ios swift ios13 ios-darkmode
我可以使用任何视图或ViewController的TraitCollection获取userInterfaceStyle。黑暗或光明。但是,当我强制应用程序使用暗或亮模式时,那么我想知道iOS设备与应用程序无关的当前userInterfaceStyle是什么?
我尝试了UIScreen的Traitcollection,但仍提供应用程序的userInterfaceStyle而不是设备。
试试看UIScreen.main,迅捷的5个例子:
// OS-wide theme available on iOS 13.
@available(iOS 13.0, *)
var osTheme: UIUserInterfaceStyle {
return UIScreen.main.traitCollection.userInterfaceStyle
}
Run Code Online (Sandbox Code Playgroud)