Search code examples
iosobjective-cios7uinavigationbaruistatusbar

Setting the same background colour on UIStatusBar as UINavigationBar


I am looking to set a background colour on the UIStatusBar in my app and I want it to match the background colour of the UINavigationBar, same as the Facebook and Instagram apps.

I tried adding this function to the didFinishLaunchingWithOptions method in my AppDelegate:

-(void) setStatusBarColour{

    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,self.window.rootViewController.view.frame.size.width, 20)];
        view.backgroundColor=[[UIColor lightGrayColor] colorWithAlphaComponent:0.6];
        [self.window.rootViewController.view addSubview:view];
    }
} 

It doesn't seem to be working.

Is there an easy way to do this?


Solution

  • On iOS 7 background colour of status bar inherits from colour of navigation bar. So You can do something like this

    [[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];

    And check out this link:http://www.appcoda.com/customize-navigation-status-bar-ios-7/