iOS8中的状态栏为黑色
我对状态栏的行为有点困惑 我不需要透明的状态栏 我需要它是黑色的。 和iOS6一样 我试了很多, 我得到的, 只有在我第一次启动应用程序时才会显示黑色, 当我将设备旋转到横向,然后再次旋转到纵向时,它将采用导航栏的颜色 我做错了什么 谁能给我指路吗 这就是我得到的 这就是我想要的iOS8中的状态栏为黑色,ios,xcode,ios8,ios7-statusbar,Ios,Xcode,Ios8,Ios7 Statusbar,我对状态栏的行为有点困惑 我不需要透明的状态栏 我需要它是黑色的。 和iOS6一样 我试了很多, 我得到的, 只有在我第一次启动应用程序时才会显示黑色, 当我将设备旋转到横向,然后再次旋转到纵向时,它将采用导航栏的颜色 我做错了什么 谁能给我指路吗 这就是我得到的 这就是我想要的 您可以通过黑客设置状态栏颜色,苹果不会拒绝该应用程序,但不能保证苹果不会在下一个iOS版本中改变这种行为 - (void)setStatusBarColor:(UIColor *)color { id statusB
您可以通过黑客设置状态栏颜色,苹果不会拒绝该应用程序,但不能保证苹果不会在下一个iOS版本中改变这种行为
- (void)setStatusBarColor:(UIColor *)color {
id statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"_statusBarWindow"];
NSString *statusBarWindowClassString = NSStringFromClass([statusBarWindow class]);
if ([statusBarWindowClassString isEqualToString:@"UIStatusBarWindow"]) {
NSArray *statusBarWindowSubviews = [statusBarWindow subviews];
for (UIView *statusBarWindowSubview in statusBarWindowSubviews) {
NSString *statusBarWindowSubviewClassString = NSStringFromClass([statusBarWindowSubview class]);
if ([statusBarWindowSubviewClassString isEqualToString:@"UIStatusBar"]) {
[statusBarWindowSubview setBackgroundColor:color];
}
}
}
}
这是一个针对iOS8、Swift和Xcode 6.3的解决方案 添加背景色:
var statusBarBackground = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 30))
statusBarBackground.backgroundColor = UIColor.blackColor()
statusBarBackground.tag = 13
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window!.rootViewController!.view.addSubview(statusBarBackground)
appDelegate.window!.rootViewController!.view.bringSubviewToFront(navigationController!.navigationBar)
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
for sv in appDelegate.window!.rootViewController!.view.subviews {
if sv.tag == 13 {
sv.removeFromSuperview()
}
}
删除背景色:
var statusBarBackground = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 30))
statusBarBackground.backgroundColor = UIColor.blackColor()
statusBarBackground.tag = 13
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window!.rootViewController!.view.addSubview(statusBarBackground)
appDelegate.window!.rootViewController!.view.bringSubviewToFront(navigationController!.navigationBar)
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
for sv in appDelegate.window!.rootViewController!.view.subviews {
if sv.tag == 13 {
sv.removeFromSuperview()
}
}
为什么我不将statusBarBackground添加到viewController的视图中?因为我在UIDocumentInteractionController预览视图中需要它,现在它不允许任何定制
为什么我要将背景设置为30高,从而迫使我在导航栏上做一个BringSubview到Front?因为我的导航栏有圆角(带有遮罩层,所以不是图像),因此显示导航栏后面的视图(我希望与状态栏背景颜色相同)
还有待解决:如果点击预览,导航栏会向上移动,但(当然)statusVarBackground会保留。没有代表告诉我预览被点击。如果你有任何想法,请将其保留在评论中。你不能这样做。如果你想这样做,那么你必须在同一帧添加视图(0,0,宽度,20)背景为黑色。并设置
查看基于控制器的状态栏外观=NO
和[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];