I have already a light and dark theme in my app. I also supported iOS 13 dark mode, the problem is, even when the light or dark mode of the app is selected, changing iOS theme leads to change status bar color, so when the ios dark mode is on, the status bar is invisible in the light theme in my app. I tried to prevent it by this block of codes, but it won't work in my case:
override var preferredStatusBarStyle: UIStatusBarStyle {
switch Appearance.theme {
case .dark:
return .lightContent
case .light:
if #available(iOS 13.0, *) {
return .darkContent
} else {
return .default
}
case .apple:
return .default
}
}
I added it in he split view controller, I also add it in each controller but nothing changes. Does anyone have any idea how to fix it?
I aslo have same problem for UITabbar
and UISegmentedControl
Somehow I should say that when the light and dark mode in my app is selected, changing iOS theme should effect in the app element (status bar, tabbar, UISegmentedControl)
Many Thanks
Go to Your info. plist file. Add a key called “View controller-based status bar appearance” and set its value to NO.
You can change the status bar colour just with a single line of code. Just updated the markdown for iOS 13 and below.
You can use overrideUserInterfaceStyle
to force controllers to adopt a specific style in iOS13
.
To solve your problem, your code should be like that:
override var preferredStatusBarStyle: UIStatusBarStyle {
switch Appearance.theme {
case .dark:
return .lightContent
case .light:
if #available(iOS 13.0, *) {
return .darkContent
} else {
return .default
}
case .apple:
return .default
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 13.0, *) {
switch Appearance.theme {
case .dark:
overrideUserInterfaceStyle = .dark
case .light:
overrideUserInterfaceStyle = .light
case .apple:
overrideUserInterfaceStyle = .unspecified
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With