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

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

    My solution was to add a UIView with height of 20 points on top of the window when on iOS 7. Then I created a method in my AppDelegate class to show/hide the "solid" status bar background. In application:didFinishLaunchingWithOptions::

    // ...
    
    // Add a status bar background
    self.statusBarBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.window.bounds.size.width, 20.0f)];
    self.statusBarBackground.backgroundColor = [UIColor blackColor];
    self.statusBarBackground.alpha = 0.0;
    self.statusBarBackground.userInteractionEnabled = NO;
    self.statusBarBackground.layer.zPosition = 999; // Position its layer over all other views
    [self.window addSubview:self.statusBarBackground];
    
    // ...
    return YES;
    

    Then I created a method to fade in/out the black status bar background:

    - (void) showSolidStatusBar:(BOOL) solidStatusBar
    {
        [UIView animateWithDuration:0.3f animations:^{
            if(solidStatusBar)
            {
                [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
                self.statusBarBackground.alpha = 1.0f;
            }
            else
            {
                [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
                self.statusBarBackground.alpha = 0.0f;
            }
        }];
    }
    

    All I have to do now is call is [appDelegate showSolidStatusBar:YES] when needed.

提交回复
热议问题