问题
When adding status bar as light content. its appearing fine in login screen. it changes to white in login screen. after successful login I have an split view and navigation controller.
I have added the code but still it shows black.
1) added below line in view contoller.
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
2) info.plist
View controller-based status bar appearance -> NO
3) then came across this line and added this one also.
controller.navigationController?.navigationBar.barTintColor = UIColor.white
4) then came across article where it was mentioned to add extension if we need to change status bar in navigation but still nothing works
extension UINavigationController
{
override open var preferredStatusBarStyle: UIStatusBarStyle {
get {
return .lightContent
}
}
}
I have added and tried with each of them but still it shows black status bar.
回答1:
try this
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
回答2:
There's another approach to do the same.
self.navigationController?.navigationBar.barStyle = .black
The idea behind this is that UIBarStyle
figures out content color of UIStatusBar
. Upon passing .black
it figures out that background is black and UIStatusBarStyleLightContent
mode is required. And when you pass .default
it figures out that background is light and returns black content or UIStatusBarStyleDefault
.
来源:https://stackoverflow.com/questions/46485347/status-bar-light-content-doesnot-appear-in-navigation-controller-using-split-vie