How to change status bar color in iOS7

102 views Asked by At

I created a custom navigation bar and I need to change the status bar's color to be the same as the navigation bar's background color:

- (void)drawRect:(CGRect)rect {
    CGFloat logoWidth = CGRectGetWidth([self frame]) / 4;
    CGFloat logoHeight =CGRectGetHeight([self frame]) / 2;
    [kAPPLogo drawInRect:CGRectMake((CGRectGetWidth([self frame]) - logoWidth) / 2, (CGRectGetHeight([self frame]) - logoHeight) / 2, logoWidth, logoHeight)];

    self.barTintColor = kNavicationBarColor;
    self.backgroundColor = kNavicationBarColor;
}

I tried this:

self.barTintColor = kNavicationBarColor

but it did not work. Can anybody help?

2

There are 2 answers

0
Indrajeet On

Status bar background color is transparent so no need to change it and it's content color is available in only two colors white and black. To change it's content color override the method preferredStatusBarStyle like given below

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

call this method in viewDidLoad

Even then you want to change background color of status bar, you can do that by following code:

UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
statusBar.backgroundColor = [UIColor blueColor];
0
iBhavin On

There is no direct way of changing the Status Bar color. We can just choose the status bar style using the setStatusBarStyle property and choose among the three available styles :

UIStatusBarStyleDefault
UIStatusBarStyleBlackTranslucent
UIStatusBarStyleBlackOpaque

But if you change the background color of your UIWindow object and set the status bar style to UIStatusBarStyleBlackTranslucent this will set the color of status bar same as the background color of the window.

Add the following code to your AppDeligate.m file in the applicationDidFinishLaunchingWithOptions :

self.window.backgroundColor = kNavicationBarColor;
[application setStatusBarStyle:UIStatusBarStyleBlackTranslucent];