In iOS 7 the UIStatusBar
has been designed in a way that it merges with the view like this:
This may be a overwhelming problem if you use Auto layout because you can not directly manipulate frames anymore. There is a simple solution without too much work.
I ended up writing an utility method in an Utility Class and called it from all the view controllers's viewDidLayoutSubviews
Method.
+ (void)addStatusBarIfiOS7:(UIViewController *)vc
{
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
CGRect viewFrame = vc.view.frame;
if(viewFrame.origin.y == 20) {
//If the view's y origin is already 20 then don't move it down.
return;
}
viewFrame.origin.y+=20.0;
viewFrame.size.height-= 20.0;
vc.view.frame = viewFrame;
[vc.view layoutIfNeeded];
}
}
Override your viewDidLayoutSubviews
method in the view controller, where you want status bar. It will get you through the burden of Autolayout.
- (void)viewDidLayoutSubviews
{
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
[super viewDidLayoutSubviews];
[MyUtilityClass addStatusBarIfiOS7:self];
}