1

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:

  1. Make the status bar a solid color. This will not show any status bar content, it will literally just be color.

  2. 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.

user3344977
  • 3,584
  • 4
  • 32
  • 88
  • Changing status bar colour will not work if you want to change it other then white(light content) or black(default). let me know if you want to do so. – Irfan Gul Feb 06 '15 at 08:01

2 Answers2

1

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.

user3344977
  • 3,584
  • 4
  • 32
  • 88
0

The only thing you can do is change its colour or hide it. You cannot add subviews to it or hide its content.

Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99