I built my app to have a translucent navbar in iOS 6. I'd like to utilize the translucent status bar in iOS 7 and keep the app as is in iOS 6, but my content is always underneath the status bar in iOS 7, with 20px missing on the bottom. I figure that I can make the very tedious code changes that check whether the device has iOS 7 and then adjust my content accordingly, but I fear that this is going to be a lot of work.
Ideally, I'd like to add 20px of padding to the top of every view controller's view, so that the content shifts down, and still functions fine with an opaque navbar on iOS 6.
I've read the threads that exist on the subject 1 2, but none of the answers provided solved my problem.
I should note that I am NOT using Interface Builder and all my VCs are being created programmatically.
If you are using
auto layout
, then all you need to do is add aVertical Constraint
from your top most view toTop Layout Guide
as shown below and it should take care the top spacing.You can disable the view going under the top bar in ios 7 by setting the following:
You can use the new Xcode 5 feature of iOS6/7 deltas to set -20 to all your view, which will give you a similar experience. Set your views correctly for iOS7 in interface builder, and use deltas for iOS6 support.
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
Here's what I did to always pad the top of my view with 20px (height of the status bar).
I used this code in my AppDelegate's application:didFinishLaunchingWithOptions: method
Now whenever you're in iOS 7, everything will exist in the root view controller's view that is shifted 20 pixels down. You'll only have to do this once in your AppDelegate.