Making app always in light mode
Dark Mode: Adding support to your app in Swift
1. f you don’t have the time to add support for Dark mode you can simply disable it by adding the
UIUserInterfaceStyle to your Info.plist and set it to Light.2. Overriding Dark Mode per view controller
You can override the user interface style per view controller and set it to light or dark using the following code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .dark
}
}Overriding Dark Mode per view
You can do the same for a single UIView instance:
let view = UIView()
view.overrideUserInterfaceStyle = .darkOverriding Dark Mode per window
Overriding the user interface style per window can be handy if you want to disable Dark Mode programmatically:
UIApplication.shared.windows.forEach { window in
window.overrideUserInterfaceStyle = .dark
}Note that we’re making use of the windows array here as the keyWindow property on the shared UIApplication is deprecated starting from iOS 13. It’s discouraged to use it as applications can now support multiple scenes that all have an attached window.

Comments
Post a Comment