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

前端 未结 25 1188
终归单人心
终归单人心 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:27

    UPDATE(NEW SOLUTION)

    This update is the best solution of iOS 7 navigation bar problem.You can set navigation bar color example: FakeNavBar.backgroundColor = [UIColor redColor];

    Note : If you use default Navigation Controller please use old solution.

    AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
        if(NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_7_0)
        {
            UIView *FakeNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
            FakeNavBar.backgroundColor = [UIColor whiteColor];
    
            float navBarHeight = 20.0;
            for (UIView *subView in self.window.subviews) {
    
                if ([subView isKindOfClass:[UIScrollView class]]) {
                    subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height - navBarHeight);
                } else {
                    subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height);
                }
            }
            [self.window addSubview:FakeNavBar];
        }
    
        return YES;
    
    }
    

    OLD SOLUTION - IF you use previous code please ignore following Code and Image

    This is old version of iOS 7 navigation bar solution.

    I solved the problem with the following code. This is for adding a status bar. didFinishLaunchingWithOptions

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        UIView *addStatusBar = [[UIView alloc] init];
        addStatusBar.frame = CGRectMake(0, 0, 320, 20);
        addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1]; //change this to match your navigation bar
        [self.window.rootViewController.view addSubview:addStatusBar];
    }
    

    And 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.

    Enter image description here

提交回复
热议问题