I want to change background color of status bar on iOS 7, and I'm using this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[UIApplication sharedApplication].statusBarHidden = NO;
self.window.clipsToBounds = YES;
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
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);
...
...
}
When I write this it shows the status bar with a black background; I want it to have a red background.
How can change the color of the status bar to have a red background instead of black?
Objective c
This is working for me. I hope this will help you too.
for what @Teja Kumar Bethina provided is helpful, but it's better to get the height of the statusBar from UIApplication singleton like below:
While handling the background color of status bar in iOS 7, there are 2 cases
Case 1: View with Navigation Bar
In this case use the following code in your viewDidLoad method
Case 2: View without Navigation Bar
In this case use the following code in your viewDidLoad method
if your application is navigation based then you can set status bar background color red like this:
may it will help.
Call this function from ViewDidLoad passing with your status bar color.
Hope It'll help.
Here's a swift solution that uses auto layout, If your application is in portrait or landscape the bar will be the correct width. It's added to the navigation bar view as a subview hence it's offset by -20. You could add it to your navigationbar's parent view, and then the offset is not required. This example will also set the colour to be the same as the navigation bar.
Hope that helps :)