如何以编程方式快速切换到暗模式 [英] How to switch programmatically to dark mode swift

查看:107
本文介绍了如何以编程方式快速切换到暗模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的iOS应用程序中进行切换,以编程方式更改为暗或亮模式? 我正在使用Swift.

How can I make a switch to change programatically to dark or light mode in my iOS app? I'm using Swift.

推荐答案

您可以使用overrideUserInterfaceStyle属性为单个视图或视图控制器覆盖样式.但是由于该窗口也是视图,因此您可以在主窗口上设置该视图以将其强制为亮或暗模式:

You can override the style for single views or view controller using the overrideUserInterfaceStyle property. But since the window is also a view, you can set that on your main window to force it into light or dark mode:

window.overrideUserInterfaceStyle = .dark

这篇关于如何以编程方式快速切换到暗模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆