如何以编程方式检查ios设备的当前userInterfaceSt

如何以编程方式检查ios设备的当前userInterfaceSt

本文介绍了如何以编程方式检查ios设备的当前userInterfaceStyle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用任何视图或ViewController的TraitCollection获取userInterfaceStyle.黑暗或光明.但是,当我强制应用程序使用暗"或亮"模式时,我想知道与设备无关的iOS设备当前的userInterfaceStyle是什么?

I am able to get userInterfaceStyle using TraitCollection of any view or ViewController ie. Dark or Light. But when I forced app to use Dark or light Mode, then I want to know what is the current userInterfaceStyle of iOS device irrespective of app?

我尝试了UIScreen的Traitcollection,但仍提供应用程序的userInterfaceStyle而不是设备.

I tried Traitcollection of UIScreen but still its provide userInterfaceStyle of app not device.

推荐答案

尝试UIScreen.main,快速5示例:

// OS-wide theme available on iOS 13.
@available(iOS 13.0, *)
var osTheme: UIUserInterfaceStyle {
    return UIScreen.main.traitCollection.userInterfaceStyle
}

这篇关于如何以编程方式检查ios设备的当前userInterfaceStyle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:04