在基于UINavigationController的应用程序

时间:2015-06-07 00:45:26

标签: ios objective-c uinavigationcontroller uistatusbar

在我的应用程序中,我使用多种颜色(基于主题)作为UINavigationBar的色调,用于某些光线和一些暗色。在iOS7及更高版本中也可以更改状态栏颜色。

对于浅色,可以使用默认状态栏文本颜色(黑色),但对于浅色,我们需要浅色(白色)。

我已根据不同的答案尝试了许多方法,以便这样做。这些是:
 1. View controller-based status bar appearance,但它不适用于基于UINavigationControler的应用程序
 2. Setting self.navigationController.navigationBar.barStyle = UIBarStyleBlack;将状态栏文本设置为白色但一旦设置为白色就不会将颜色更改为黑色

它将如何运作?

1 个答案:

答案 0 :(得分:1)

要更改特定页面上的颜色,您需要在应用程序范围内更改它。您可以在离开本课程页面后重新更新。

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    // Do any additional setup after loading the view.
    if ([tintColor isEqual:[UIColor blackColor]])
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    else
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}

- (void) viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];

    //set it back to default
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}
相关问题