问题
How can I make a switch to change programatically to dark or light mode in my iOS app? I'm using Swift.
回答1:
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
来源:https://stackoverflow.com/questions/60171262/how-to-switch-programmatically-to-dark-mode-swift