ios – TabBarController上的彩色状态栏,导航栏无法正常工作

在这里阅读了很多帖子,并尝试了大多数提到的选项,但没有人为我解决问题.我有一个基于标签栏控制器的应用程序.每个选项卡都是一个UIViewController,顶部有一个导航栏.

将此代码添加到AppDelegate为我提供了带有白色文本的橙色导航栏,但是带有黑色文本的白色状态栏.

[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

阅读各种页面上的答案建议将以下内容添加到View控制器:

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

然后在View Did Load中调用它:

[self setNeedsstatusBarappearanceUpdate];

这让我得到一个带有白色文本的白色状态栏,我现在如何让状态栏变为橙色以匹配我的导航栏?

对于那些使用导航控制器的人来说,这里提到的解决方案不起作用,我想这是因为我的主控制器是一个标签栏控制器.

有没有人遇到过这个?提前感谢您提出的任何建议/建议.如果需要,我可以提供一个示例应用程序,但可能使用Tab Bar模板快速构建一个,添加导航栏然后粘贴我的代码示例.

等离子体

解决方法

您可以通过它的名称找到statusBar UIVIew并为其着色.将此方法添加到AppDelegate.m并从didFinishLaunchingWithOptions调用它:
- (void)setStatusBarBackgroundColor:(UIColor *)color {

    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 ...   

    [self setStatusBarBackgroundColor:[UIColor orangeColor]];

 ...

}

注意:商店中有些应用程序使用此方法.所以苹果HIG政策也没关系.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...