我想在我的应用中使用白色状态栏。为此,我将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:
VC中的代码我希望有白色状态栏(prefferdSTatusBarStyle
未调用)
VC中的代码
.plist设置
结果是黑色状态栏,隐藏在某个VC中
UPD2:
我知道使用弃用的方法很糟糕,但[[UIApplication sharedApplication] setStatusBarHidden:YES];
一切都按照我的意愿运行。如果有人有更好的解决方案,请告诉我。
答案 0 :(得分:5)
这是快速版本:
要隐藏状态栏或更改其外观,您需要在视图控制器本身中覆盖以下属性
XmlDocument doc = new XmlDocument();
doc.Load(_xmlFilePath);
XmlNodeList nodelist = doc.SelectNodes("//result[@value=45]");
for (int i = 0; i < nodelist.Count; i++)
{
double value = double.Parse(nodelist[i].InnerText);
Console.WriteLine("value : " + value);
}
如果要将状态栏设置为白色,则上面隐藏状态栏:
override var prefersStatusBarHidden: Bool{
return true
}
答案 1 :(得分:2)
在plist文件中添加View controller-based status bar appearance
Bool属性并将其设置为YES。
现在在视图控制器中添加如下方法:
// 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
}
Objective-C
- (BOOL)prefersStatusBarHidden {
return NO;
}
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
为了删除冗余代码,您可以将BaseViewController
作为UIViewController
的子类,并添加该类中的方法。并覆盖需要更改的类中的方法。
答案 2 :(得分:0)
如果你的viewcontroller嵌入在UInavigationController中,那么尝试在你的
中编写这段代码-(BOOL)prefreStatusBarHidden
{
return [self.navigationController prefersStatusBarHidden];
}
答案 3 :(得分:0)
答案 4 :(得分:-1)
您可以通过在基本视图控制器中设置导航背景图像来完成此操作。
<!DOCTYPE html>
<html ng-app="app">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../css/css.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="//unpkg.com/angular-ui-router/release/angular-ui-router.min.js"></script>
</head>
<body>
<div id="wraper" >
<div id="header">
<img src="../images/guitar1.png" id="topscreenshot" >
<input type="text" id="topinput" placeholder="Enter keywords, Item # or Catalog #">
</div>
<div id="mainpage">
<div id="navbardiv">
<span id="allnavbars" ng-mouseenter="reveal()" ng-mouseleave="notreveal()">
<a ui-sref ="home"><button class="navbarbuttons">Home</button></a>
<a ui-sref ="products"><button class="navbarbuttons">Product</button></a>
<a ui-sref ="usedgear"><button class="navbarbuttons">Used Gear</button></a>
<a ui-sref ="platinum"><button class="navbarbuttons">Platinum</button></a>
<a ui-sref ="vintage"><button class="navbarbuttons">Vintage</button></a>
<a ui-sref ="outlet"> <button class="navbarbuttons">Outlet</button></a>
<a ui-sref ="gcpro"> <button class="navbarbuttons">GC Pro</button></a>
<a ui-sref ="lessons"><button class="navbarbuttons">Lessons</button></a>
<a ui-sref ="repairs"><button class="navbarbuttons">Repairs</button></a>
<a ui-sref ="rental"><button class="navbarbuttons">Rentals</button></a>
</span>
</div>
<div id="undernavbargrey">
<span id="dropdownspan" ng-show="showsub" >
<a href="#" class="anchorsss">Guitars</a>
<a href="#" class="anchorsss">Bass</a>
<a href="#" class="anchorsss">Amps Effects</a>
<a href="#" class="anchorsss">Drums</a>
<a href="#" class="anchorsss">Recording</a>
<a href="#" class="anchorsss">Software</a>
<a href="#" class="anchorsss">keyboards MIDI</a>
<a href="#" class="anchorsss">Mics Wireless</a>
<a href="#" class="anchorsss">Live Sound</a>
<a href="#" class="anchorsss">DJ</a>
<a href="#" class="anchorsss">Lighting</a>
<a href="#" class="anchorsss">Accessories</a>
<a href="#" class="anchorsss">Band Orchestra</a>
</span>
</div>
<div ui-view>
</div>
<div id="therestdiv">
<img src="../images/therest.png" id="therestpic">
</div>
</div>
<script src = "../script/module.js"></script>
<script src="../script/controller.js"></script>
<script src="../script/route.js"></script>
<script src="../script/cdirective.js"></script>
</body>
</html>