How to change status bar background color

2019-06-10 01:43发布

问题:

Is there way to change the background color of status bar right now it show white with black icons of battery i want the color black here is the code i am using in viewDidLoad

     if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

回答1:

  1. Set UIViewControllerBasedStatusBarAppearance to NO. Call

  2. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

For more details...check this link

EDIT: try adding this

self.extendedLayoutIncludesOpaqueBars = YES;


回答2:

in iOS 7 the status Bar is transparent. Make sure the background view is Dark if you are setting UIStatusBarStyleLightContent

For more info You can check the Apple UITransition Guide



回答3:

1) set the UIViewControllerBasedStatusBarAppearance to YES in the plist

2) in viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];

3) add the following method:

-(UIStatusBarStyle)preferredStatusBarStyle
{ 
     return UIStatusBarStyleLightContent; 
} 

also check developers-guide-to-the-ios-7-status-bar



标签: ios statusbar