Search code examples
iosstatusbar

Putting a view behind the status bar


I'm trying to create a statusBar Background. However it seem to place it wrong i've set a View in the top of the viewController and applied following contraints:

-16 trailing
-16 leading
top space 0
height 24

However this is the result

enter image description here

Why is there a white space at the top?


Solution

  • You can create the background for your status bar in the next very straightforward way :

    // Set the status bar to red
    var statusBarView = UIView(frame: CGRectMake(0, 0, 1024, 22))
    statusBarView.backgroundColor = UIColor.redColor()
    self.view.addSubview(statusBarView)
    

    Put in the above code in your viewDidLoad() it should be work. I put the 1024 size for the width of the UIView but you can change it according your needs of the device you want.

    I hope this help you.