You simply add a UIView
to the current view with the correct statusBar measurements and then change the color.
Here's some sample code.
First get the status bar's frame:
//The statusBarFrame returns the frame in screen coordinates. I believe the correct way to get what this corresponds to in view coordinates is to do the following:
- (CGRect)statusBarFrameViewRect:(UIView*)view
{
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect statusBarWindowRect = [view.window convertRect:statusBarFrame fromWindow: nil];
CGRect statusBarViewRect = [view convertRect:statusBarWindowRect fromView: nil];
return statusBarViewRect;
}
//source: http://stackoverflow.com/questions/3888517/get-iphone-status-bar-height
Then create your view in the viewDidload method or whenever you hide your navigation bar with the following code:
UIView *statusBarUnderLay = [[UIView alloc] initWithFrame:[self statusBarFrameViewRect:self.view]];
[statusBarUnderLay setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:statusBarUnderLay];
and voila