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

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

    This may be a overwhelming problem if you use Auto layout because you can not directly manipulate frames anymore. There is a simple solution without too much work.

    I ended up writing an utility method in an Utility Class and called it from all the view controllers's viewDidLayoutSubviews Method.

    + (void)addStatusBarIfiOS7:(UIViewController *)vc
        {
            if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
                CGRect viewFrame = vc.view.frame;
                if(viewFrame.origin.y == 20) {
                    //If the view's y origin is already 20 then don't move it down.
                    return;
                }
                viewFrame.origin.y+=20.0;
                viewFrame.size.height-= 20.0;
                vc.view.frame = viewFrame;
                [vc.view layoutIfNeeded];
            }
        }
    

    Override your viewDidLayoutSubviews method in the view controller, where you want status bar. It will get you through the burden of Autolayout.

    - (void)viewDidLayoutSubviews
    {
        [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
        [super viewDidLayoutSubviews];
        [MyUtilityClass addStatusBarIfiOS7:self];
    }
    

提交回复
热议问题