Updates on 19th Sep 2013:
fixed scaling bugs by adding
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
corrected typos in the NSNotificationCenter
statement
Updates on 12th Sep 2013:
corrected UIViewControllerBasedStatusBarAppearance
to NO
added a solution for apps with screen rotation
added an approach to change the background color of the status bar.
There is, apparently, no way to revert the iOS7 status bar back to how it works in iOS6.
However, we can always write some codes and turn the status bar into iOS6-like, and this is the shortest way I can come up with:
Set UIViewControllerBasedStatusBarAppearance
to NO
in info.plist
(To opt out of having view controllers adjust the status bar style so that we can set the status bar style by using the UIApplicationstatusBarStyle method.)
In AppDelegate's application:didFinishLaunchingWithOptions
, call
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
//Added on 19th Sep 2013
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}
return YES;
in order to:
Check if it's iOS 7.
Set status bar's content to be white, as opposed to UIStatusBarStyleDefault.
Avoid subviews whose frames extend beyond the visible bounds from showing up (for views animating into the main view from top).
Create the illusion that the status bar takes up space like how it is in iOS 6 by shifting and resizing the app's window frame.
For apps with screen rotation,
use NSNotificationCenter to detect orientation changes by adding
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidChangeStatusBarOrientation:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
in if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)
and create a new method in AppDelegate:
- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{
int a = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue];
int w = [[UIScreen mainScreen] bounds].size.width;
int h = [[UIScreen mainScreen] bounds].size.height;
switch(a){
case 4:
self.window.frame = CGRectMake(0,20,w,h);
break;
case 3:
self.window.frame = CGRectMake(-20,0,w-20,h+20);
break;
case 2:
self.window.frame = CGRectMake(0,-20,w,h);
break;
case 1:
self.window.frame = CGRectMake(20,0,w-20,h+20);
}
}
So that when orientation changes, it will trigger a switch statement to detect app's screen orientation (Portrait, Upside Down, Landscape Left, or Landscape Right) and change the app's window frame respectively to create the iOS 6 status bar illusion.
To change the background color of your status bar:
Add
@property (retain, nonatomic) UIWindow *background;
in AppDelegate.h
to make background
a property in your class and prevent ARC from deallocating it. (You don't have to do it if you are not using ARC.)
After that you just need to create the UIWindow in if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)
:
background = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, self.window.frame.size.width, 20)];
background.backgroundColor =[UIColor redColor];
[background setHidden:NO];
Don't forget to @synthesize background;
after @implementation AppDelegate
!
UIStatusBarDefault
for the status bar only makes its content black in color. It is not going to make the way it functions back to how it is in iOS6. – Archy Will He 何魏奇