UIViewControllerBasedStatusBarAppearance的默认值为YESYES的情况下,使用代码进行设置是无效的。

解决方案

info.plistView controller-based status bar appearance 键值设置为NO,即可在代码中对状态栏进行设置。

如隐藏状态栏

1
[[UIApplication sharedApplication] setStatusBarHidden:YES];

官方文档

UIViewControllerBasedStatusBarAppearance
  • UIViewControllerBasedStatusBarAppearance (Boolean - iOS) Specifies whether the status bar appearance is based on the style preferred by the view controller that is currently under the status bar. When this key is not present or its value is set to YES, the view controller determines the status bar style. When the key is set to NO, view controllers (or the app) must each set the status bar style explicitly using the UIApplication object.