I am using a UINavigationController
and showing navigation bars throughout my app, but I do not want to show a status bar to the user. My problem is if I hide the status bar, then the navigation bar size is not big enough to give the appearance of a full navigation bar.
I would like to do one of the following:
Make the status bar a solid color. This will not show any status bar content, it will literally just be color.
Add a subview to the status bar so that I can cover all of it's "status" content. This subview would just be a UIView that was a solid color.
This would allow me to have the full size "nav bar" at the top, without having to actually show status bar content.
EDIT:
I have been trying the following UIWindow
workaround with no luck. The following code is being called inside one of my view controller's viewWillAppear:
method:
UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
statusWindow.windowLevel = UIWindowLevelStatusBar + 1;
statusWindow.hidden = NO;
statusWindow.backgroundColor = [UIColor redColor];
[statusWindow makeKeyAndVisible];
I can't get this to work. Am I supposed to be hiding the status bar, or showing it? I have tried both hiding and showing it with the above code and my red colored UIWindow
never shows on screen.
I finally figured it out. This code does work perfectly:
self.statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
self.statusWindow.windowLevel = UIWindowLevelStatusBar + 1;
self.statusWindow.hidden = NO;
self.statusWindow.backgroundColor = [UIColor redColor];
[self.statusWindow makeKeyAndVisible];
The key is, statusWindow
cannot just be a local variable. It needs to be an actual property, otherwise it is deallocated from memory.
Also for what it's worth, I don't even have to call makeKeyAndVisible
to get this to appear.