UIStatusBarStyle changes after displaying a UIWindow over UIStatusBar

跟風遠走 提交于 2020-01-12 06:35:07

问题


I am displaying a UIWindow over the UIStatusBar, by default the UIStatusBarStyle is set to UIStatusBarStyleLightContent, but when I display the UIWindow the UIStatusBarStyle switches to the black style.


回答1:


I came across this topic while struggling with the same problem. What you have to do is create a new view controller and set it as the root view controller of your UIWindow (that is the UIWindow that you are displaying over your other view). Then, in this new view controller implement the preferredStatusBarStyle method like this:

- (UIStatusBarStyle) preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

Alternatively, you can set the "View controller-based status bar appearance" property in Info.plist to NO and implement the [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent] method as Azabella suggested. However, this will set the Status Bar of all your views to white. If that's no problem, then there's no need to make a separate view controller just to set the preferredStatusBarStyle method.




回答2:


Did you set the "View controller-based status bar appearance" property in yourAppName-Info.plist to NO ?




回答3:


This was a fairly trivial problem that I found to be resolved setting modalPresentationCapturesStatusBarAppearance to true.




回答4:


Add this so when the view appears it will set the colour/style

-(void)viewDidAppear:(BOOL)animated {

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}


来源:https://stackoverflow.com/questions/19617122/uistatusbarstyle-changes-after-displaying-a-uiwindow-over-uistatusbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!