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

前端 未结 25 1379
终归单人心
终归单人心 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条回答
  •  猫巷女王i
    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.

提交回复
热议问题