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
Xcode Hide white status bar ios 10
提问by Ossir
I want white status bar in my app. For this I set View controller-based status bar appearance
to NO
and Status bar style
to 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 appearance
to YES
and add - (BOOL)prefersStatusBarHidden {return YES;}
. But status bar is black now. It's black when View controller-based status bar appearance
is YES
and white if NO
. So the question is, how to set white status bar and hide it?
我想在我的应用程序中使用白色状态栏。为此,我设置View controller-based status bar appearance
到NO
和Status bar style
到UIStatusBarStyleLightContent
。但是现在我需要在某些视图控制器中隐藏状态栏。要隐藏它,我必须设置View controller-based status bar appearance
为YES
并添加- (BOOL)prefersStatusBarHidden {return YES;}
. 但是状态栏现在是黑色的。View controller-based status bar appearance
是的时候是黑色的,如果是YES
白色的NO
。那么问题来了,如何设置白色状态栏并隐藏呢?
UPD:
code in VC that I want to have white status bar (prefferdSTatusBarStyle
not called)
UPD:我想要白色状态栏的 VC 代码(prefferdSTatusBarStyle
未调用)
code in VC with hidden status bar
VC中隐藏状态栏的代码
.plist settings
.plist 设置
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 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 appearance
Bool property and set it to YES.
在您的 plist 文件中添加View controller-based status bar appearance
Bool 属性并将其设置为 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 BaseViewController
as subclass of UIViewController
and 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];