Why doesn't my iOS app disable dark mode?

前端 未结 3 1887
礼貌的吻别
礼貌的吻别 2021-02-14 09:04

So ... I\'ve tried to set my app to disable iOS 13 dark mode by forcing light mode according apple documentation, in the emulator all attempts work fine, but when I try on the r

相关标签:
3条回答
  • 2021-02-14 09:39

    Simply you can add a new key UIUserInterfaceStyle in your app info.plist and set its value to Light or Dark. this will override the app default style to the value you provide.

    so you don't need to bother about having it anywhere else

    0 讨论(0)
  • 2021-02-14 09:45
    if #available(iOS 13, *) {
        window.overrideUserInterfaceStyle = .light
    }
    

    Should work. Call it in your AppDelegate's didFinishLaunchingWithOptions.

    0 讨论(0)
  • 2021-02-14 09:59

    Change the window UserInterfaceStyle for iOS 13+ version. Just set

    UIApplication.shared.changeStatusBarStyle(.light)
    

    or

    UIApplication.shared.changeStatusBarStyle(.dark)
    

    after changing window every time.

    extension UIApplication {
    
            enum StatusColor {
    
                case dark, light
            }
    
            func changeStatusBarStyle(_ mode: StatusColor = .light) {
    
                if #available(iOS 13.0, *) {
    
                    guard let appDelegate = delegate as? AppDelegate else { return }
    
                    var interfaceStyle: UIUserInterfaceStyle
    
                    switch mode {
                    case .dark:
                        interfaceStyle = .dark
                    default:
                        interfaceStyle = .light
                    }
    
                    appDelegate.window?.overrideUserInterfaceStyle = interfaceStyle
                }
            }
        }
    

    If any confusion please let me know.

    0 讨论(0)
提交回复
热议问题