Pregunta

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?

¿Fue útil?

Solución

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/

Otros consejos

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]];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top