如何在子视图控制器中更改iOS状态栏颜色 [英] How to change iOS status bar color in child view controller

查看:406
本文介绍了如何在子视图控制器中更改iOS状态栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(iOS 7 Xcode 5.0.2)

(iOS 7 Xcode 5.0.2)

我使用以下方法,在根视图控制器上成功将状态栏颜色更改为白色

I used following methods, successfully change the status bar color to white on root view controller

[self setNeedsStatusBarAppearanceUpdate]; // Update status bar style

-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent; // Set status bar color to white
}

(导航到子视图控制器时,栏颜色为黑色,我不知道该怎么做)(状态栏颜色仍为白色)

Now I'm trying to change status bar color to black when navigate to child view controller, I don't know how to do it.(status bar color is still white)

方法: childViewControllerForStatusBarStyle
我读了苹果的文档,但仍然不知道如何/在哪里使用它,我不知道这是否是正确的方法

I searched, and find this method: childViewControllerForStatusBarStyle I read Apple's document,But still don't know how to/where to use it, and I'm not sure if this is the right approach

任何人都知道如何在子视图控制器中更改状态栏颜色。

Anyone knows how to change status bar color in child view controller?

推荐答案

,似乎 UINavigationController 不幸地没有提供一个明智的默认实现 childViewControllerForStatusBarStyle 。通过实现此方法,您可以告诉您的navigationController将对 preferredStatusBarStyle 的所有调用延迟到其最高的childViewController。

By default, it seems that UINavigationController unfortunately doesn't provide a sensible default implementation of childViewControllerForStatusBarStyle. By implementing this method, you can tell your navigationController to defer all calls to preferredStatusBarStyle to its topmost childViewController.

可以子类化 UINavigationController 并实现该方法,或者只是添加一个类别:

You could either subclass UINavigationController and implement the method there, or simply add a category:

@implementation UINavigationController (ChildStatusBarStyle)

- (UIViewController *)childViewControllerForStatusBarStyle 
{
    return self.topViewController;
}

@end

这篇关于如何在子视图控制器中更改iOS状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆