In iOS 7 the UIStatusBar
has been designed in a way that it merges with the view like this:
(GUI designed by Tina Tavčar)
It is cool, but it will somewhat mess up your view when you have something at the top part of your view, and it becomes overlapped with the status bar.
Is there a simple solution (such as setting a property in info.plist) that can change the way it works [not overlapping] back to how it is in iOS6?
I know a more straightforward solution is to have
self.view.center.x
+ 20 points for every single view controller, but changing them will screw other dimensions up (having a differentself.view.center.x
can cause problem to custom segues, etc.) and suddenly it turns into a tedious job that is best to be avoided.I'll really be glad if someone can provide me an one-liner solution for this.
P.S. I know I can hide the status bar by doing things like having
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
In didFinishLaunchingWithOptions
method, but that's a workaround, a shortcut avoiding the problem, so I don't consider that a real solution.
A small alternative to Archy Holt's answer, a bit more simple:
a. Set
UIViewControllerBasedStatusBarAppearance
toNO
in info.plistb. In
AppDelegate
'sapplication:didFinishLaunchingWithOptions:
, call:And add the method:
You can also consider subclassing
UIWindow
to handleUIApplicationDidChangeStatusBarOrientationNotification
itself.I used this in all my view controllers, it's simple. Add this lines in all your viewDidLoad methods:
My very simple solution (assuming you have only vertical orientation supported) is to redefine application window bounds for iOS versions below 7, in App delegate didFinishLaunchingWithOptions method:
I solved the problem with the following code. This is for adding a status bar. didFinishLaunchingWithOptionsAnd for Interface Builder this is for when you open with iOS 6; it is starting at 0 pixels.Note: iOS 6/7 Deltas only appear if you uncheck "Use Autolayout" for the View Controller in the "File Inspector" (left-most icon) in the details pane.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
toNO
ininfo.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
, callin 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
in
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)
and create a new method in AppDelegate: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
in
AppDelegate.h
to makebackground
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)
:Don't forget to
@synthesize background;
after@implementation AppDelegate
!Here another approach for projects that make extensive use of the Storyboard:
GOAL:
Goal of this approach is to recreate the same status bar style in iOS7 as there was in iOS6 (see question title "iOS 7 Status Bar Back to iOS 6 style?").
SUMMARY:
To achieve this we use the Storyboard as much as possible by shifting UI elements that are overlapped by the status bar (under iOS 7) downwards, whilst using deltas to revert the downwards layout change for iOS 6.1 or earlier. The resulting extra space in iOS 7 is then occupied by a UIView with the backgroundColor set to a color of our choosing. The latter can be created in code or using the Storyboard (see ALTERNATIVES below)
ASSUMPTIONS:
To get the desired result when following the steps below, it is assumed that
View controller-based status bar appearance
is set to NO and that yourStatus bar style
is either set to "Transparent black style (alpha of 0.5)" or "Opaque black style". Both settings can be found/or added under "Info" in your project settings.STEPS:
Add a subview to the UIWindow to serve as your status bar background. To achieve this, add the following to your AppDelegate's
application: didFinishLaunchingWithOptions:
aftermakeKeyAndVisible
Since you programmatically added a background for iOS 7 ONLY, you will have to adjust the layout of your UI elements that are overlapped by the status bar accordingly whilst preserving their layout for iOS6. To achieve this, do the following:
Use Autolayout
is unchecked for your Storyboard (this is because otherwise "iOS 6/7 Deltas" is not shown in the Size Inspector). To do this:ALTERNATIVES:
To add even less code in storyboard-heavy projects and to have the statusbar background autorotate, instead of programmatically adding a background for your statusbar, you could add a colored view to each view controller that sits at the very top of said viewcontroller's main view. You would then change the height delta of this new view to the same negative amount as your view's height (to make it disappear under iOS 6).
The downside of this alternative (although maybe negligible considering the autorotate compatibility) is the fact that this extra view is not immediately visible if you are viewing your Storyboard for iOS 6. You would only know that it's there if you had a look at the "Document Outline" of the Storyboard.