How to set status bar hidden for entire app in iOS

2020-08-01 05:10发布

问题:

I am trying to set the status bar of my entire iOS app hidden. (The app deployment target is set to iOS 7.1).

I have tried the following (and none worked):

Adding this line to application:didFinishLaunchingWithOptions: in AppDelegate.m :

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

and also this line:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

I have tried setting the statusBar to None for each of my View Controllers in Storyboard View --> Attributes inspector --> Simulated Metrics.

I have tried adding the key Status bar is initially hidden as YES in Info.plist file of my app.

None of these worked. Can anyone guide me as to what is wrong? Btw, I am using the latest version of XCode on my Mac and latest iOS on my test device. And, all my View Controllers have been set to Landscape mode only in Attributes inspector. And the supported orientations of the app are Landscape both sides.

回答1:

Just set both properties in your .plist file.Then you will be good to go.

1.View controller-based status bar appearance -No

2.Status bar is initially hidden-YES

Hope this will help!



回答2:

Have you tried setting:

View controller-based status bar appearance

to NO In your Info.plist file?



回答3:

In your info.plist file, there's a setting called "Status bar is initially hidden." Set that to "YES," and you won't have it at startup. Then you don't need to do anything in your code, the bar will show up when your app is launched.