Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Updates on 19th Sep 2013:</p> <p><sub> fixed scaling bugs by adding <code>self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);</code> </sub></p> <p><sub> corrected typos in the <code>NSNotificationCenter</code> statement </sub></p> </blockquote> <p><br></p> <blockquote> <p>Updates on 12th Sep 2013:</p> <p><sub>corrected <code>UIViewControllerBasedStatusBarAppearance</code> to <code>NO</code></sub></p> <p><sub>added a solution for apps with screen rotation</sub></p> <p><sub>added an approach to change the background color of the status bar.</sub></p> </blockquote> <p><br></p> <p>There is, apparently, no way to revert the iOS7 status bar back to how it works in iOS6. </p> <p>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:</p> <ol> <li><p>Set <code>UIViewControllerBasedStatusBarAppearance</code> to <code>NO</code> in <code>info.plist</code> (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.)</p></li> <li><p>In AppDelegate's <code>application:didFinishLaunchingWithOptions</code>, call</p> <pre><code>if (NSFoundationVersionNumber &gt; 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; </code></pre></li> </ol> <p><br></p> <p>in order to:</p> <ol> <li><p>Check if it's iOS 7.</p></li> <li><p>Set status bar's content to be white, as opposed to UIStatusBarStyleDefault.</p></li> <li><p>Avoid subviews whose frames extend beyond the visible bounds from showing up (for views animating into the main view from top).</p></li> <li><p>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.</p></li> </ol> <p><br></p> <h2>For apps with screen rotation,</h2> <p>use NSNotificationCenter to detect orientation changes by adding</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidChangeStatusBarOrientation:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; </code></pre> <p>in <code>if (NSFoundationVersionNumber &gt; NSFoundationVersionNumber_iOS_6_1)</code> and create a new method in AppDelegate:</p> <pre><code>- (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); } } </code></pre> <p>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.</p> <p><br></p> <h2>To change the background color of your status bar:</h2> <p>Add</p> <pre><code> @property (retain, nonatomic) UIWindow *background; </code></pre> <p>in <code>AppDelegate.h</code> to make <code>background</code> a property in your class and prevent ARC from deallocating it. (You don't have to do it if you are not using ARC.)</p> <p>After that you just need to create the UIWindow in <code>if (NSFoundationVersionNumber &gt; NSFoundationVersionNumber_iOS_6_1)</code>:</p> <pre><code>background = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, self.window.frame.size.width, 20)]; background.backgroundColor =[UIColor redColor]; [background setHidden:NO]; </code></pre> <p>Don't forget to <code>@synthesize background;</code> after <code>@implementation AppDelegate</code>!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload