📜  暗模式立即更改 swift 代码示例

📅  最后修改于: 2022-03-11 15:01:03.689000             🧑  作者: Mango

代码示例1
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
   return
}
appDelegate.changeTheme(themeVal)


// App Delegate Change Theme method
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
     }
  }
}