0

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?

Rameez Hussain
  • 6,414
  • 10
  • 56
  • 85

2 Answers2

5

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/

Zhans
  • 273
  • 2
  • 11
  • Ah nice. I was playing around with this function and was also setting the backgroundColor property of the navigation bar instead of the bar tint colour. But it works now. Thanks! :) – Rameez Hussain Jan 25 '14 at 11:25
2

You don't need to write extra code for that. once you change color of navigationBar, statusBar will adapt the same color & tints for the fonts automatically.

How to change color of navigationBar?

Follow this link

and this is Facebook bar color Hex code : #3B5998

So your code would be :

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:59 green:89 blue:152 alpha:1]];
Community
  • 1
  • 1
Prince Agrawal
  • 3,619
  • 3
  • 26
  • 41