swift detect dark mode change code example
Example 1: disable dark mode swift
if #available(iOS 13.0, *) {
UIWindow.appearance().overrideUserInterfaceStyle = .light
}
Example 2: dark mode change immediately swift
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
appDelegate.changeTheme(themeVal)
func changeTheme(themeVal: String) {
if #available(iOS 13.0, *) {
switch themeVal {
case "dark":
window?.overrideUserInterfaceStyle = .dark
break
case "light":
window?.overrideUserInterfaceStyle = .light
break
default:
window?.overrideUserInterfaceStyle = .unspecified
}
}
}