I want to change background color of status bar on iOS 7, and I\'m using this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp
In iOS 7 and later, the status bar is transparent. Set the backgroundColor
of your view to the color you want for the status bar.
Or, you can add a 20px-high subview with red color at the top of your view.
See the Apple Transition Guide for more.
Also, make sure that your preferredStatusBarStyle
is UIStatusBarStyleLightContent
. and in your Info.plist set "View controller-based status bar appearance" to "NO".
While handling the background color of status bar in iOS 7, there are 2 cases
Case 1: View with Navigation Bar
In this case use the following code in your viewDidLoad method
UIApplication *app = [UIApplication sharedApplication];
CGFloat statusBarHeight = app.statusBarFrame.size.height;
UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight, [UIScreen mainScreen].bounds.size.width, statusBarHeight)];
statusBarView.backgroundColor = [UIColor yellowColor];
[self.navigationController.navigationBar addSubview:statusBarView];
Case 2: View without Navigation Bar
In this case use the following code in your viewDidLoad method
UIApplication *app = [UIApplication sharedApplication];
CGFloat statusBarHeight = app.statusBarFrame.size.height;
UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, statusBarHeight)];
statusBarView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:statusBarView];