如何去除statusBar 实现app全屏幕显示

It’s really easy to hide the status bar on your iPhone and iPad apps.  You can do this using several approaches:

  1. Programmatically using the statusBarHidden property in the UIApplication class.
  2. Use the target summary settings to turn off the status bar for the entire app target.
  3. Add a property and value to your App-info.plist file.

We will cover all three of these approaches very quickly in the post.

UIApplication statusBarHidden property

It’s really easy to control the status bar within your application.  You can perform these actions in your AppDelegate file, or in a particular view if necessary.  To hide the status bar, use the following line of code:

1
[[UIApplication sharedApplication] setStatusBarHidden:YES];

Keep in mind that even if you put this line of code in your AppDelegate, the status bar will still be shown during the launching of your app.  To hide the status bar throughout your application, or just during the launch, you will need to set the setting using the target summary settings or by modifying the App-info.plist file.  Use the setStatusBarHidden:withAnimation: If you want to animate the showing/hiding of the status bar.

You can also use the setStatusBarStyle:animated: method to control the appearance of the status bar.  There are 3 different constants that control the style of the status bar:

  1. UIStatusBarStyleDefault
  2. UIStatusBarStyleBlackTranslucent
  3. UIStatusBarStyleBlackOpaque

Target summary settings

Browse to your target summary settings by clicking on the project title in the project navigator pane.  Then, click on the target for your application, and choose the summary tab.

You can set the visibility and style of the status bar using the settings for each deployment target (iPhone/iPod versus iPad).  This will hide the status bar during the application launch and throughout your application.

App-info.plist

You can also manually control the application settings using the information property list.  You can find documentation on the apple web site that lists all of the application settings for iOS apps that can be controlled using the application information property list.  The file is found in your project’s “Supporting Files” group and is named: ${Project_name}-info.plist.

If you click on the file in Xcode, it will open the file in the property list editor.  Using this approach you can add keys and values.  You can also right-click (or control-click) on the file in Xcode and choose Open As > Source Code.  This way you can view the XML stored in the plist file.  Add the following XML as a child of the <dict> node:

1
2
3
4
<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarHidden~ipad</key>
<true/>

This will hide the status bar for both iPhone and iPad apps.

你可能感兴趣的:(如何去除statusBar 实现app全屏幕显示)