iOS7中的UIStatusBar会改变颜色

时间:2014-03-07 05:16:25

标签: ios ios7 background uinavigationbar uistatusbar

我正在使用UINavigationController

对于rootViewController,我将navigationBar设为透明

enter image description here

[self.view setBackgroundColor:[UIColor greenColor]];
self.navigationController.navigationBar.shadowImage = [UIImage new];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

问题是,当我导航到第二个viewController

enter image description here

[self.navigationController.navigationBar setBackgroundColor:[UIColor greenColor]];

此处我将navigationBar颜色设置为绿色,但状态栏不会显示在绿色背景中。

是否可以将状态栏背景更改为绿色?

2 个答案:

答案 0 :(得分:3)

[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];

请尝试此link

答案 1 :(得分:2)

在AppDelegate的didFinishLaunchingWithOptions方法中写这个

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    // Override point for customization after application launch.
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        UIView *addStatusBar = [[UIView alloc] init];
        addStatusBar.frame = CGRectMake(0, 0, 320, 20);
        //change this to match your navigation bar or view color or tool bar
        //You can also use addStatusBar.backgroundColor = [UIColor BlueColor]; or any other color
        addStatusBar.backgroundColor = [UIColor colorWithRed:0.973.0/255. green:0.973.0/255. blue:0.973.0/255. alpha:1];
        [self.window.rootViewController.view addSubview:addStatusBar];
    }
    return YES;
}

并编写以下代码,您可以在其中设置状态栏的背景颜色。首先创建appdelegate的对象并使用它进行调用。

appdelegate.addStatusBar.backgroundColor = [UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:1];

Refer this: