Xcode Hide white status bar ios 10

让人想犯罪 __ 提交于 2019-12-01 16:39:41

you can set using xcode status bar style is "light"

This is the swift version:

To hide the status bar or change it's appearance, you need to override the following properties in your view controller itself

override var prefersStatusBarHidden: Bool{
        return true
}

the above hides the status bar and below if you want to set it to white:

override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
}

In your plist file add View controller-based status bar appearance Bool property and set it to YES.

Now in your view controller add the methods like below:

// TO MAKE STATUS BAR WHITE
override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return .LightContent
}

// TO MAKE STATUS BAR BLACK
override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return .LightContent
}

// RETURN TRUE TO HIDE AND FALSE TO SHOW STATUS BAR
override func prefersStatusBarHidden() -> Bool {
        return true
}

For Objective-C

- (BOOL)prefersStatusBarHidden {
    return NO;
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

For removing redundant code you can make a BaseViewController as subclass of UIViewController and add the methods in that class. And override the method in the class which requires change.

if your viewcontroller is embedded in UInavigationController then try writing this code in your

-(BOOL)prefreStatusBarHidden
{
       return [self.navigationController prefersStatusBarHidden];
}

You can do this by setting the navigation background image in your base viewcontroller.

UIImage *bgImage = [UIImage imageNamed:@"bg_navigationbar"];
[self.navigationController.navigationBar setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!