7

I know it's possible to remove a status bar, however the frame shifts up by the height of the status bar if you set it to hidden. As such, the following code:

[UIApplication sharedApplication].statusBarHidden = YES;

is not sufficient for just hiding the text of the status bar. What I'm ultimately attempting to accomplish here is something similar to the Gmail app in which as the side-menu is displayed, the status bar text is hidden, and then once a selection is made the frame returns to normal with the status bar text displayed.

This question shows how to animate the hiding of the status bar but the result is that the entire window shifts up by the height of the status bar. I'm trying to avoid that from happening.

Community
  • 1
  • 1
Nick ONeill
  • 7,341
  • 10
  • 47
  • 61

3 Answers3

8

Objective-C version:

[AppDelegate instance].window.windowLevel = UIWindowLevelStatusBar;

Swift version:

AppDelegate().window!.windowLevel = UIWindowLevelStatusBar
Rajesh Kumar
  • 821
  • 12
  • 20
2

This should do it. It's a bit of a hack, however:

NSString *key = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char []){0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72} length:9] encoding:NSASCIIStringEncoding];
id object = [UIApplication sharedApplication];
UIView *statusBar;
if ([object respondsToSelector:NSSelectorFromString(key)]) {
     statusBar = [object valueForKey:key];
}
[UIView animateWithDuration:0.3
                     animations:^{
                         statusBar.alpha = 0.0f; 
                     }
];
runmad
  • 14,846
  • 9
  • 99
  • 140
  • `(unsigned char []){0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72}` ... why not just `"statusBar"` or whatever those ASCII chars are? Guessing it says status bar.. `0x74 = 0x73 + 1` and `t = s + 1` – James Webster Dec 22 '13 at 20:09
  • 2
    Because this gets around Apple's checks. – runmad Dec 22 '13 at 20:37
  • 3
    Terrible solution, whether it is getting around Apple's checks or not. What happens in iOS7.1? 7.2? 8.0? – Léo Natan Dec 23 '13 at 04:59
  • 2
    You mean this solution is based on circumventing an Apple static analysis check for the string `statusBar`? Terrible solution! I down vote not because it's necessarily a wrong answer, but not future proof and I can't advocate it. – James Webster Dec 23 '13 at 09:44
1

Somehow applying the following code in my code result of nil while unwrapping optional

AppDelegate().window!.windowLevel = UIWindowLevelStatusBar

I have used the following to make status bar text hide :

UIApplication.shared.delegate?.window!!.windowLevel = UIWindowLevelStatusBar 

And to reset status bar to default and show the text :

UIApplication.shared.delegate?.window!!.windowLevel = UIWindowLevelNormal
AaoIi
  • 8,288
  • 6
  • 45
  • 87