2

How to cover also the UIStatusBar with UIView when i cover all the screen with the UIView?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Shay
  • 2,595
  • 3
  • 25
  • 35

4 Answers4

6

I was battling how to do this for a long time too! Finally figured it out :) The key is to set the windowLevel of your new window to really high so it lives on top of all the other windows/views/statusbar etc:

UIWindow *keyWin = [UIApplication sharedApplication].keyWindow;
UIWindow *hudWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0.0f, 0.0f, keyWin.frame.size.width, keyWin.frame.size.height)];
hudWindow.backgroundColor = [UIColor blackColor];
hudWindow.alpha = 0.60;
[hudWindow setWindowLevel:10000.0f];
[hudWindow setHidden:NO];

Enjoy!

Sahil
  • 1,268
  • 12
  • 19
  • I dug a little further, and found that the windowLevel property has some constants that represent certain levels: const UIWindowLevel UIWindowLevelNormal; const UIWindowLevel UIWindowLevelAlert; const UIWindowLevel UIWindowLevelStatusBar; I found UIWindowLevelStatusBar does the trick. – Sahil Apr 20 '10 at 00:56
  • Note that if you call `keyWindow` when the app launches, it is possible for the value to be nil. Better to use `[[UIScreen mainScreen] bounds]` to get the window frame. – ThomasW Aug 02 '13 at 10:18
  • This does not work when the keyboard is on the screen. – Rafał Sroka Mar 25 '14 at 14:04
2

The best thing you can do is hide the status bar with:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]

and show it again when you need it.

You can basically removeFromSuperview any time you want to remove the view.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
David Sowsy
  • 1,680
  • 14
  • 13
0

If you're trying to create a UIAlertView-like effect, I don't think you can do this. You might file a feature enhancement request with Apple at http://bugreporter.apple.com.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
0

Nice, but I made these two changes. Adding 1.0 to UIWindowLevel still hides the status bar, and I have no idea why.

self.windowLevel = UIWindowLevelStatusBar+2.0f;

self.userInteractionEnabled = NO;

Setting the Statusbar userInteractionEnabled property to NO will ensure that your scroll views will scroll to top when someone taps on this statusbar.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mugunth
  • 14,461
  • 15
  • 66
  • 94