Xcode 隐藏白色状态栏 ios 10

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41670828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:43:38  来源:igfitidea点击:

Xcode Hide white status bar ios 10

iosobjective-cxcodeios10statusbar

提问by Ossir

I want white status bar in my app. For this I set View controller-based status bar appearanceto NOand Status bar styleto UIStatusBarStyleLightContent. But now I need to hide status bar in some view controllers. To hide it I have to set View controller-based status bar appearanceto YESand add - (BOOL)prefersStatusBarHidden {return YES;}. But status bar is black now. It's black when View controller-based status bar appearanceis YESand white if NO. So the question is, how to set white status bar and hide it?

我想在我的应用程序中使用白色状态栏。为此,我设置View controller-based status bar appearanceNOStatus bar styleUIStatusBarStyleLightContent。但是现在我需要在某些视图控制器中隐藏状态栏。要隐藏它,我必须设置View controller-based status bar appearanceYES并添加- (BOOL)prefersStatusBarHidden {return YES;}. 但是状态栏现在是黑色的。View controller-based status bar appearance是的时候是黑色的,如果是YES白色的NO。那么问题来了,如何设置白色状态栏并隐藏呢?

UPD: code in VC that I want to have white status bar (prefferdSTatusBarStylenot called)

UPD:我想要白色状态栏的 VC 代码(prefferdSTatusBarStyle未调用)

enter image description here

在此处输入图片说明

code in VC with hidden status bar

VC中隐藏状态栏的代码

enter image description here

在此处输入图片说明

.plist settings

.plist 设置

enter image description here

在此处输入图片说明

Result is black status bar, that hides in some VC

结果是黑色状态栏,隐藏在某些 VC 中

UPD2:

UPD2:

I know it's bad to use deprecated methods but with [[UIApplication sharedApplication] setStatusBarHidden:YES];everything works as I want. If anyone have better solution please let me know.

我知道使用不推荐使用的方法很糟糕,但[[UIApplication sharedApplication] setStatusBarHidden:YES];一切都按我的意愿工作。如果有人有更好的解决方案,请告诉我。

采纳答案by Birendra

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

您可以使用 xcode 状态栏样式设置为“浅色”

enter image description here

在此处输入图片说明

回答by Shawn Frank

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
}

回答by Parth Adroja

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

在您的 plist 文件中添加View controller-based status bar appearanceBool 属性并将其设置为 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

对于Objective-C

- (BOOL)prefersStatusBarHidden {
    return NO;
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

For removing redundant code you can make a BaseViewControlleras subclass of UIViewControllerand add the methods in that class. And override the method in the class which requires change.

为了删除冗余代码,您可以创建一个BaseViewController子类UIViewController并在该类中添加方法。并覆盖类中需要更改的方法。

回答by Nishant Tiwari

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

如果您的视图控制器嵌入在 UInavigationController 中,请尝试在您的

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

回答by Lewanny

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];