iosxcodeios8ios7-statusbar

black colour for status bar in iOS8


I am little bit confused about the status bar behaviour

I don't need transparent status bar I need it fixed and black colour. Same like iOS6

I tried a lot, what I get it, its showing black colour only when I launch the app first time, when I rotate the device to landscape and again make to portrait then it takes the navigation bar colour.

What I am doing wrong.

Can any one please guide me.

This is what I am getting

enter image description here

This is how I want

enter image description here


Solution

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