To disable dark mode for the iOS app, we can simply set UIUserInterfaceStyle
in Info.plist to Light
.
But how do I disable dark mode on specific UIViewController
's?
To disable dark mode for the iOS app, we can simply set UIUserInterfaceStyle
in Info.plist to Light
.
But how do I disable dark mode on specific UIViewController
's?
You can force viewController to act as you want. In viewDidLoad
you have to follow this code to change UserInterfaceStyle
Objective-C
if (@available(iOS 13.0, *)) {
[self setOverrideUserInterfaceStyle: UIUserInterfaceStyleLight];
}
Swift
if #available(iOS 13.0, *) {
overrideUserInterfaceStyle = .light
}
If you want to disable dark mode on specific view controllers than you have to put this code in viewcontroller's viewDidLoad method
override func viewDidLoad() {
super.viewDidLoad()
// overrideUserInterfaceStyle is available with iOS 13
if #available(iOS 13.0, *) {
// Always adopt a light interface style.
overrideUserInterfaceStyle = .light
}
}
Instead of disabling it, you can use following code to make it look like it is disabled
if #available(iOS 13.0, *)
{
self.view.overrideUserInterfaceStyle = .light
// This will solve the problem (Current View will never be in dark mode
}