我对状态栏中的文本颜色有疑问。我想让文本的颜色变白,但在模态视图上保持黑色。
我有下一个配置:
- 设置为“Opens in 5.1”和“Project Deployment target 7.0”和“View as iOS7 and later”的 Storyboard
UITabBarViewController
- 4
UINavigationControllers
- 每个导航 Controller 都有
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
的返回值更改为 UIStatusBarStyleDefault
(好吧,我知道它应该将文本绘制成黑色,但我还是试过了)
将 Status Bar 选项设置为 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 上的这个类别很管用。
关于iOS7 导航栏+状态栏文字颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21432622/