Here's a solution for iOS8, Swift, Xcode 6.3.
Add a background color:
var statusBarBackground = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 30))
statusBarBackground.backgroundColor = UIColor.blackColor()
statusBarBackground.tag = 13
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window!.rootViewController!.view.addSubview(statusBarBackground)
appDelegate.window!.rootViewController!.view.bringSubviewToFront(navigationController!.navigationBar)
Remove the background color:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
for sv in appDelegate.window!.rootViewController!.view.subviews {
if sv.tag == 13 {
sv.removeFromSuperview()
}
}
Why didn't I just add statusBarBackground to the viewController's view? Because I needed this for the UIDocumentInteractionController Preview view, which, as it stands now, does not allow for any customization.
Why did I make statusBarBackground 30 high, thus forcing me to do a bringSubviewToFront for the navigationBar? Because my navigationbar has rounded corners (with mask layers, so not images), thus showing the view behind the navigation bar (which I want to be the same color as the statusbar background.
Still to figure out: If you tap the preview the nav bar moves up, but (of course) the statusVarBackground remains. No delegates that tell me the preview was tapped. If you have any idea, leave it in the comments.