IOS:StatusBar
lastmod 2018-08-17created 2014-02-1020 edits
The status bar displays important information about the device and the current environment (shown below on iPhone).
Status Bar Black Error
This section summarizes how to fix the status bar (StatusBar) being rendered black, as in the image below.
Ios7_statusbar_error_sample.png
- See "iOS7 StatusBar Style" below
- See the "Hide Status Bar" section of UIViewController: change the return value of the
prefersStatusBarHiddenfunction toNOso the StatusBar is shown.
iOS7 StatusBar Style
With the update to IOS7, a few more things became controllable, and one of them is the StatusBar. It is defined in UIViewController as follows.
// These methods control the attributes of the status bar when this view controller is shown. They can be overridden in view controller subclasses to return the desired status bar attributes.
- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarStyleDefault
Override this function as follows.
iOS7 StatusBar Overlap Issue
With the iOS version update, the position of the status bar changed due to differences between versions 6 and 7. The status bar, which occupied a fixed 20px area in version 6, seems to have changed in version 7 to use an overlapping area instead of a fixed one. As a fix, add the following to the didFinishLaunchingWithOptions function of AppDelegate.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
// [application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds = YES;
self.window.frame = CGRectMake(0, 20, self.window.frame.size.width,self.window.frame.size.height - 20);
self.window.bounds = CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height);
}
Or it can be fixed simply as follows.
CGRect frame = self.navigationController.view.frame;
frame.origin.y = 20;
self.navigationController.view.frame = frame;
Favorite site
Technical Q&A: iOS7 StatusBar
- Developer apple: Preventing the Status Bar from Covering Your Views
- Developer apple: UIBarPositioningDelegate Protocol Reference
iOS7 StatusBar Issues
- iOS 7 status bar back to iOS 6 style's issue 1
- iOS 7 status bar back to iOS 6 style? 2
- Status bar and navigation bar issue in IOS7 3
- IOS7_StatusBar and CustomNavigationBar 4
- iOS 7 Development Tips, Tricks & Hacks