How to set Status bar background color iOS 7

52,840

Solution 1

You have to do 2 things. First is to open your info.plist and set "View controller-based status bar appearance" = NO

And the second is to add this lines to application:didFinishLaunchingWithOptions

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{   
    self.window.clipsToBounds = YES;
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];     

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        self.window.frame =  CGRectMake(20, 0,self.window.frame.size.width-20,self.window.frame.size.height);
        self.window.bounds = CGRectMake(20, 0, self.window.frame.size.width, self.window.frame.size.height);
    } else
    {
        self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
        self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
    }
}

Solution 2

Read this article: http://www.appcoda.com/customize-navigation-status-bar-ios-7/

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]  

[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
Share:
52,840
SWT
Author by

SWT

i'm a iPhone and iPad Application Developer...

Updated on July 05, 2022

Comments

  • SWT
    SWT almost 2 years

    iOS 6 look...

    enter image description here

    Same way i would like to display status bar in iOS 7 like

    see this

    enter image description here

    but My actual output (Overlap)

    i have tried following logic

    open your info.plist and set "View controller-based status bar appearance" = NO
    

    it's not working in my code,,,

  • SWT
    SWT over 10 years
    my apps run in Landscape mode. but your code appear black bar right and left side
  • Stanislav
    Stanislav over 10 years
    Updated an answer to support both orientations.
  • SWT
    SWT over 10 years
    but working fine... but when i rotate screen that was not changing based on screen orientation
  • Stanislav
    Stanislav over 10 years
    You should register for statusbarorientationchanged notification and use the same code over there. I can not write the app instead of you, I already gave you an answer, so you should get it's point and use it accordingly to your needs.
  • capikaw
    capikaw over 10 years
    Excellent link for those devs putting images on their UINavigationBar.
  • cynistersix
    cynistersix over 10 years
    Sadly didn't do much for my iPad application. Good link though
  • mindbomb
    mindbomb about 10 years
    actually the key you have to add to info.plist is: UIViewControllerBasedStatusBarAppearance = NO
  • Fraggle
    Fraggle over 9 years
    For some reason this isn't working for me, storyboard, ios7. Added that line to AppDelegate didFinishLaunching