32

I tried to test my app in iOS 7, and then I find my view appears over the status bar... As I read, in iOS 7, the status bar is hidden. So how do I make it compatible to run both in iOS 6 and iOS 7? Should I have to make different .xib files for different iOS versions for each screen?

I have been going through reading this: If both versions of a standard app should have a similar layout, use Auto Layout to create a UI that works correctly in both versions of iOS. To support multiple versions of iOS, specify a single set of constraints that Auto Layout can use to adjust the views and controls in the storyboard or XIB files (to learn more about constraints, see “Constraints Express Relationships Between Views”).

If both versions of a standard app should have a similar layout, and you’re not using Auto Layout, use offsets. To use offsets, first update the UI for iOS 7. Next, specify values that define the origin, height, and width of each element in the earlier UI as offsets from the element’s new position in the iOS 7 UI.

But when I use autolayout in .xib, it shows an error that autolayout is in a prior version to iOS 6.

How do I fix this problem?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Bhrigesh
  • 841
  • 1
  • 7
  • 14
  • 2
    You should ask ios7 related questions to apple developer forum because it's still under NDA. – cahn Aug 22 '13 at 09:07
  • See this link : http://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios-7 – Nishith Shah Aug 22 '13 at 09:16
  • @Developer i already go through this link.. it will status bar in light grey color.. but my issue is set my ui screen frame ... as my whole screen 20 pixel up... in ios7 but coming normal in ios6 ... – Bhrigesh Aug 22 '13 at 09:34
  • So there is something like bug in Xcode5-DP. I am facing same issue. – Nishith Shah Aug 22 '13 at 09:36
  • This video explains it - https://www.youtube.com/watch?v=FtpBXdMSqRQ The fix explains how to get the status bar hidden for iOS 6 and iOS 7 at the same time. –  Aug 28 '13 at 20:21
  • This link has interesting info on this issue: http://www.doubleencore.com/2013/09/developers-guide-to-the-ios-7-status-bar/ – lucasart Sep 25 '13 at 09:37

6 Answers6

37

iOS 7 apparently supports the Status Bar being hidden for some views but not others. To hide it for all views, do the following:

  1. Make sure Hide during application launch is still checked, to support previous OS versions.
  2. In your Info.plist file, add View controller-based status bar appearance and set it to NO.
  3. You may need to "Clean" before building, (I did), but then your app should work as before: no status bar hanging over your views!
Cory Foy
  • 7,072
  • 4
  • 28
  • 34
Nerrolken
  • 1,884
  • 3
  • 22
  • 49
  • 4
    This worked for me except that the status bar reappears after showing a UIImagePicker. – Swindler Sep 12 '13 at 05:34
  • 1
    Ah, found the answer for the image picker issue here: http://stackoverflow.com/a/18747724/455794 – Swindler Sep 12 '13 at 05:53
  • 2
    This appears to fully hide the status bar which I don't want to do. Ideally, I would just like to shift down my content so the status bar doesn't hover over it and overlap my app header. FYI I'm making a phonegap/cordova app. – njtman Sep 12 '13 at 14:17
  • @njtman You can do this following this link: http://stackoverflow.com/questions/17074365/status-bar-and-navigation-bar-appear-over-my-views-bounds-in-ios-7 – crubio Sep 23 '13 at 14:14
  • Point 2) alone allowed me to hide the status bar on iOS7 and move my view 'back down the screen' and now it's all as I want it. Thanks a lot. (I have no Nav bar, just the status bar) – Stephen Watson Oct 25 '13 at 15:56
  • You are a legend,..u saved me. thank you. – Murali Nov 29 '13 at 12:55
24

You probably need to add the following code on each view controller.

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
    {
        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
    else
    {
        // iOS 6
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    }
}

// Add this method
- (BOOL)prefersStatusBarHidden {
    return YES;
}
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
NIKHIL
  • 2,725
  • 1
  • 24
  • 49
  • 1
    Just adding the prefersStatusBarHidden method was enough. – SG1 Sep 17 '13 at 20:46
  • 1
    @SG1 preferesStatusBarHidden is only available for ios7 so i think you would like your application to work on ios 6 as well till devices all over world having ios7 ;-) – NIKHIL Sep 18 '13 at 04:24
  • It is quite keeping None for the status bar in xib as no status bar is showing. Why do you need almost 10 lines of code for that.. we should require the handling of status bar in iOS 6 and iOS 7 by showing status bar not to hide.. – Srinivas G Sep 23 '13 at 13:04
9

I have the same issue. For now I made two hacks and will decide with which I'll go:

  • You can hide status bar completely by setting UIStatusBarHidden and UIViewControllerBasedStatusBarAppearance to true.
  • In my app, I created a Top Spacing constraint with value 0, and I programmaticaly change it to 20 if I detect that the app is running on iOS 7.

How do I make Autolayout account for the status bar area?


Well, I figured it out.

In your sub-view (BRSMyListSubViewController in my case), in viewDidLoad, you need to set one of these two

self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;

OR

self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;

Interestingly enough, in the root view controller, these values are set to default UIRectEdgeAll, NO and YES respectively, but its tableView is NOT under navbar and footer.

I don't know why it's so illogical.

It's also strange that edgesForExtendedLayout has to be mixed with one of two other properties even though it's clearly responsible for the behavior.

expert
  • 26,897
  • 27
  • 105
  • 198
8

If you like to show a status bar under iOS 7 with Xcode 5, just rearrange the buttons and other subviews to make enough space around the status bar. But, just wait! I like to support iOS 6 too. How do I do that?

I found documentation from Apple, and found the "Supporting Two Versions of a Standard App" title in the document.

If you are editing an XIB file, select it and click assistant editor. You will able to find the "manual, automatic..." menu around there. Then choose "preview".

Enter image description here

Then you'll find a view layout side by side. Then you will notice that there is a popup button around the right bottom of the right pane (view); it says "iOS 7 and later". You can choose "iOS 6.1 and earlier". Woa! Now you can make adjustments for iOS 6.1 without affecting the layout of iOS 7.

Enter image description here

If you are working on the storyboard, it is basically the same. You choose a view controller object, and click assistant editor mode, choose "preview", then "iOS7 and later"... Bluh Bluh Bluh.

I'm not sure, but only the assistant editor is capable of switching to iOS 7+/iOS 6- mode. I just found this very recently, so please point out, if there are any misunderstandings or other tricks.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Kaz Yoshikawa
  • 1,362
  • 15
  • 21
  • 3
    "Now you can make adjustment for iOS 6.1 without affecting the layout of iOS 7". I don't think this is true. It's just a preview tool. – Danyal Aytekin Sep 20 '13 at 09:44
  • Option for "iOS 7 and later" can also be found at `File inspector` of View Controller for storyboard – RootCode Dec 17 '13 at 07:28
3

There is no need to build multi-xib. I think your problem is the "20px": the same XIB file looks great in iOS 6, but it misses 20 pixels in iOS 7.

For example, you have a view, and it's Y = 0. In iOS 6, it's next to the bottom of the status bar. In iOS 7, it appears over the status bar.

You should use Xcode 5 to open your XIB files and enable assistant editor. Follow these steps:

  1. Select file inspector, and switch "View As" to "iOS 7 and later"

  2. Select size inspector, and fill deltaY with "-20"

  3. It's done!

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
DongXu
  • 1,271
  • 13
  • 12
  • 2
    this sounds like it should work, but I cannot get it to work on my iPhone 5 w/ iOS 7 GM, app built with Xcode 5 GM. Your solution seems to have no effect. I tried cleaning the project too. – njtman Sep 12 '13 at 14:31
  • This did the trick :) but you have to set in each view/subview of the xib. – Everton Cunha Sep 19 '13 at 16:54
  • There is an answer with some code on a related entry. @Stunner stackoverflow.com/a/18976660/235206 has the solution – MiKL Oct 01 '13 at 14:56
0

You just once need to check your main UIView size for iOS 7.0 & later & iOS 6.0 & lower, probably you will get idea.

From iOS 7 Apple has changed main view size = fixed It means if you add navigation bar, tabbar your view size remains same [iPhone 4s : 320 *480, iPhone 5 : 320 * 568].

imDeveloper
  • 776
  • 1
  • 6
  • 16