[英]iOS7 Navigation Bar + Status Bar Text Color
状态栏中的文本颜色有问题。 我想让文字颜色变白,但在模态视图上保持黑色。
我有下一个配置:
UITabBarViewController
UINavigationControllers
UIViewController
自定义子类 UINavigationBar的背景颜色通过appearance
设置为暗。
View controller-based status bar appearance
设置为YES
我的UITabBarViewController
子类有下面的方法:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
应用程序启动后调用这些方法。
我在UIViewControllers
子类中也有相同的方法调用:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent; // This method never called
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
我还试图将-preferredStatusBarStyle
返回值-preferredStatusBarStyle
为UIStatusBarStyleDefault
(好吧,我知道它应该用黑色绘制文本,但我还是试过了)
将状态栏选项设置为Storyboard中的Light Content也是一样的。 也行不通。
我知道有很多关于SO的问题与我的相似,但提出的解决方案对我的情况没有帮助。
我的状态栏仍然如下所示:
而我想将其颜色更改为白色= /
这是我在与这个问题斗争了大约2周之后偶尔发现的一个解决方法。
// This is a workaround just enables white text colour in status bar in iOS7, iOS7.1
// Dont touch it until things break
// Despite this category says "draw white", colour automatically becomes black on white background w/o additional code
@interface UINavigationController (StatusBarStyle)
@end
@implementation UINavigationController (StatusBarStyle)
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
@end
// Place at the bottom of your AppDelegate.m
// Magic!
我要感谢那些回答这个问题的人,但我已经尝试过这些解决方案并且他们没有帮助:( UINavigationController上的这个类别正常。
首先,你说- (UIStatusBarStyle)preferredStatusBarStyle
永远不会在你的UIViewController
子类中调用。 这是正常的。 您的根视图控制器将调用此方法。 在您的情况下,它是UITabBarViewController
。
您还说您已尝试set Status Bar option to Light Content in Storyboard
。 如果仔细观察,您应该在名为Simulated metrics
的部分中完成此操作。 正如标题所示,这里的修改是模拟的......
我建议你尝试在Info.plist中添加密钥UIViewControllerBasedStatusBarAppearance
并将其设置为YES。
您需要在RootViewController中设置它:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.