I want to have one feature in my app. I decided to create UIAlertController and 2 AlertAction: Light Mode and Dark Mode. How I can change mode in whole my app by clicking one of my AlertAction. Please Help ....
Asked
Active
Viewed 549 times
1
-
1refer this link : https://stackoverflow.com/questions/47500989/adding-dark-mode-to-ios-app – Tanjima Kothiya Dec 21 '19 at 11:37
1 Answers
2
@available(iOS 13.0, *)
func changeMode() {
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "DARK MODE", style: .default, handler: { action in
UIWindow.animate(withDuration: 0.5, animations: {
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .dark
//also try : UIApplication.shared.windows.last?.overrideUserInterfaceStyle = .dark
})
}))
alertController.addAction(UIAlertAction(title: "LIGHT MODE", style: .default, handler: { action in
UIWindow.animate(withDuration: 0.5, animations: {
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .light
//UIApplication.shared.windows.last?.overrideUserInterfaceStyle = .light
})
}))
self.present(alertController, animated : true)
}

Celeste
- 1,519
- 6
- 19
-
Thank you very much, but can you help with animations, because this code makes changing very quickly and sharply. – Аба-Бакри Ибрагимов Dec 23 '19 at 03:23
-
I tried this solution, but iOS animations are different. For example when I want to change iOS mode in settings it's working very smoothly and beautiful . where I can find this solution ? – Аба-Бакри Ибрагимов Dec 23 '19 at 08:43
-