在AppDelegate中我有應用顏色:重新加載的AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let defaults = UserDefaults.standard
let switchState = defaults.integer(forKey: "switchState")
if switchState == 1 {
UINavigationBar.appearance().barTintColor = UIColor.black
UIApplication.shared.statusBarStyle = .lightContent
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]
UITabBar.appearance().barTintColor = UIColor.black
UISearchBar.appearance().barStyle = UIBarStyle.black
UITextField.appearance().keyboardAppearance = UIKeyboardAppearance.dark
}
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
return true
}
使滑塊打開「暗模式」。但要使更改生效,應用程序必須重新啓動。如何在不重新啓動應用程序的情況下執行此操作?
我想滑塊一旦打開立即更改UI暗。 –