Add UIView banner above status bar iOS 7

Mike V picture Mike V · Mar 7, 2014 · Viewed 16.1k times · Source

I'm trying to add a banner above the status bar when receiving an in-app push notification. From what I've been reading, it seems like the only way to dynamically change the status bar style in iOS 7 is to set UIViewControllerBasedStatusBarAppearance to NO. This is not only really annoying to have to change all my different view controllers prefersStatusBarHidden to [UIApplication sharedApplication].statusBarHidden, but it also doesn't give the effect I'm looking for.

When the banner slides from the top, I still want the 20 pts of space that the status bar provides to stay, but the status bar content to disappear until after the banner slides back up. Is there a way to either do this or add a subview or window above the status bar?

Basically I'm looking to do this:

Facebook Messenger push banner

Answer

Nico picture Nico · Mar 25, 2014

To put your view controller above status bar:

[[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar+1];

To put your view controller behind status bar:

[[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelNormal];