带有NavigationBar的TabBarController上的彩色状态栏无效

Pla*_*sma 7 objective-c statusbar ios

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

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

[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
Run Code Online (Sandbox Code Playgroud)

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

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
Run Code Online (Sandbox Code Playgroud)

然后在View Did Load中调用它:

[self setNeedsStatusBarAppearanceUpdate];
Run Code Online (Sandbox Code Playgroud)

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

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

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

等离子体

Pla*_*sma 1

是的,BSmith11 提出的关于将导航控制器添加到选项卡栏的观点引起了我的思考。所以我做了一些谷歌搜索,并在这个页面上找到了一个答案,很有帮助:Tab bar control inside a uinavigationcontroller

通过将 TabBar 控制器作为 rootViewController,然后在它和普通 ViewController 之间插入一个“NavigationController”,我可以做到这一点:

    //Fix up the Navigation bar tint and set text colours to white
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor orangeColor]];

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

//Also requires setting 'View controller-based status bar appearance' to NO in .plist
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Run Code Online (Sandbox Code Playgroud)

这正是我之前所拥有的,它给了我一个彩色的状态栏和完全相同颜色的导航栏。现在看看我是否可以将其添加到现有的应用程序中而不破坏所有内容。

等离子体