iOS7 导航栏+状态栏文字颜色

标签 ios cocoa ios7 ios7-statusbar

我对状态栏中的文本颜色有疑问。我想让文本的颜色变白,但在模态视图上保持黑色。

我有下一个配置:

  • 设置为“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 的问题与我的类似,但建议的解决方案对我的情况没有帮助。

我的状态栏仍然是这样的:

StatusBar

我想把它的颜色改成白色=/

最佳答案

这是我在为这个问题苦苦挣扎了大约 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/

相关文章:

objective-c - 如何关闭 NSOpenPanel 或为什么它不自动关闭?

android - Login with Facebook option trigger 建议下载一个应用程序

ios - 在本地通知中点击后无法在特定 View Controller 中打开应用程序

objective-c - cocoa WebView SWF

iphone - 关闭我的应用程序 (OSX) 后继续收到 "This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation."

ios7 - IOS7 中的 UINavigationBar/状态栏问题

iOS 应用程序 : access to Music storage allowed?

ios - 钥匙串(keychain) SecOSStatusWith 错误 :[-34018]

ios - 在锁屏iOS7上显示音乐播放控件的最佳方法

ios - 将日本标准时间的 24 小时制时间格式转换为 12 小时制时间格式