iOS 7 status bar back to iOS 6 default style in iPhone app?

前端 未结 25 852
终归单人心
终归单人心 2020-11-22 05:48

In iOS 7 the UIStatusBar has been designed in a way that it merges with the view like this:

\"GUI

相关标签:
25条回答
  • 2020-11-22 06:21

    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:

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    if ([HMService getIOSVersion] < 7) {
        // handling statusBar (iOS6) by leaving top 20px for statusbar.
        screenBounds.origin.y = 20;
        self.window = [[UIWindow alloc] initWithFrame:screenBounds];
    }
    else {
        self.window = [[UIWindow alloc] initWithFrame:screenBounds];
    }
    
    0 讨论(0)
  • 2020-11-22 06:21

    This might be too late to share, but I have something to contribute which might help someone, I was trying to sub-class the UINavigationBar and wanted to make it look like ios 6 with black status bar and status bar text in white.

    Here is what I found working for that

            self.navigationController?.navigationBar.clipsToBounds = true
            self.navigationController?.navigationBar.translucent = false
            self.navigationController?.navigationBar.barStyle = .Black
            self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
    

    It made my status bar background black, status bar text white and navigation bar's color white.

    iOS 9.3, XCode 7.3.1

    0 讨论(0)
  • 2020-11-22 06:23

    If you don't want your view controllers to be overlapped by the status bar (and navigation bars), uncheck the "Extend Edges Under Top Bars" box in Interface Builder in Xcode 5.

    Uncheck the Extend Edges Under Top Bars

    0 讨论(0)
  • 2020-11-22 06:24

    A small alternative to Archy Holt's answer, a bit more simple:

    a. Set UIViewControllerBasedStatusBarAppearance to NO in info.plist

    b. In AppDelegate's application:didFinishLaunchingWithOptions:, call:

    if ([[UIDevice currentDevice].systemVersion floatValue] < 7)
    {
        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    else
    {
        // handling statusBar (iOS7)
        application.statusBarStyle = UIStatusBarStyleLightContent;
        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
        self.window.clipsToBounds = YES;
    
        // handling screen rotations for statusBar (iOS7)
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
    }
    

    And add the method:

    - (void)applicationDidChangeStatusBarOrientationNotification:(NSNotification *)notification
    {
        // handling statusBar (iOS7)
        self.window.frame = [UIScreen mainScreen].applicationFrame;
    }
    

    You can also consider subclassing UIWindow to handle UIApplicationDidChangeStatusBarOrientationNotification itself.

    0 讨论(0)
  • 2020-11-22 06:24

    There is an option in the Interface Builder which calls the iOS 6/7 Delta property which aim to solve the offset problem.

    Take a look at it in Stack Overflow question Interface Builder: What are the UIView's Layout iOS 6/7 Deltas for?.

    0 讨论(0)
  • 2020-11-22 06:24

    If you're using Interface builder, try this:

    In your xib file:

    1) Select the main view, set the background color to black (or whatever color you want the status bar to be

    2) Make sure the background is a self contained subview positioned as a top level child of the controller's view.
    Move your background to become a direct child of the controller's view. Check the autosizing panel to be sure that you've locked all frame edges, activated both flexibility axes, and if this is a UIImageView, set the content mode to Scale to fill. Programmatically this translates to contentMode set to UIViewContentModeScaleToFill and has its auto resizing mask set to (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight).

    3) Now move everything that is locked to the top - down by 20 pts and set a iOS 6/7 delta Y to -20.
    All top level children that are locked to the top frame in the autosizing panel need to be moved down by 20pts and have their iOS 6/7 delta Y set to -20. (Cmd select all of those, and click down arrow 20 times - is there a better way anyone?)

    4) Adjust the iOS 6/7 delta height of all of the above items that had a flexible height. Any of the items that were locked to the frame top and bottom and had flexible height enabled in the autosizing panel must also have their iOS 6/7 delta height set to 20. That includes the background view mentioned above. This may seem anti-intuitive, but due to the order in which these are applied, it is necessary. The frame height is set first (based on device), then the deltas are applied, and finally the autosizing masks are applied based upon the offset positions of all of the child frames - think it through for a bit, it will make sense.

    5) Finally, items that were locked to the bottom frame but not the top frame need no deltas at all.

    That will give you the identical status bar in iOS7 and iOS6.

    On the other hand, if you want iOS7 styling while maintaining iOS6 compatibility, then set the delta Y / delta height values to 0 for the background view.

    To see more iOS7 migration info read the full post: http://uncompiled.blogspot.com/2013/09/legacy-compatible-offsets-in-ios7.html

    0 讨论(0)
提交回复
热议问题