In iOS 7 the UIStatusBar
has been designed in a way that it merges with the view like this:
Apple released Technical Q&A QA1797: Preventing the Status Bar from Covering Your Views. It works fine for the iOS 6 and iOS 7 versions.
Try this simple method....
Step 1:To change in single viewController
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
Step 2: To change in whole application
info.plist
----> Status Bar Style
--->UIStatusBarStyle to UIStatusBarStyleBlackOpaque
Step 3: Also add this in each viewWillAppear
to adjust statusbar
height for iOS7
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7) {
CGRect frame = [UIScreen mainScreen].bounds;
frame.origin.y+=20.0;
frame.size.height-= 20.0;
self.view.frame = frame;
[self.view layoutIfNeeded];
}
Steps For Hide the status bar in iOS 7:
1.Go to your application info.plist file.
2.And Set, View controller-based status bar appearance : Boolean NO
Hope i solved the status bar issue.....
In order to continue working with setStatusBarHidden: I use this category:
@interface UIApplication (StatusBar)
-(void)setIOS7StatusBarHidden:(BOOL)statusBarHidden;
@end
@implementation UIApplication (StatusBar)
-(void)setIOS7StatusBarHidden:(BOOL)statusBarHidden{
if (!IOS7) {
[self setStatusBarHidden:statusBarHidden];
return;
}
if ([self isStatusBarHidden] == statusBarHidden) {
return;
}
[self setStatusBarHidden:statusBarHidden];
[self keyWindow].clipsToBounds = YES;
CGFloat offset = statusBarHidden ? 0 : 20;
[self keyWindow].frame = CGRectMake(0,offset,[self keyWindow].frame.size.width,[self keyWindow].frame.size.height-offset);
[self keyWindow].bounds = CGRectMake(0, offset, [self keyWindow].frame.size.width,[self keyWindow].frame.size.height);
}
@end
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];
}
You can hide the status bar all together. So your app will be full-screen. I think that's the best you will get.
UIStatusBarStyleNone
or set in the target settings.