1
InViewDidLoad
    UIApplication.sharedApplication().statusBarStyle = .LightContent

 override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)

        UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default

    }

By taking reference of above link i have implemented.But the statusbar color is not changing only text On Statusbar is changing. Changing the Status Bar Color for specific ViewControllers using Swift in iOS8

Community
  • 1
  • 1
Pavani
  • 61
  • 5

2 Answers2

1

There is no separate background view behind the status bar as default. It is actually just overlay over the top of your main view and so the background takes the colour of this.

So if you have a view embedded in a navigation controller it will just take the colour of the navigation bar. If not, then it will just take the colour of the main view.

You could create a separate view that sits at the top beneath the status bar and set the background of this.

As Michael said, the following code should do it but I've changed the width to be the width of the device so it works in all situations.

var statusBarView: UIView = UIView(frame: CGRectMake(0.0, 0.0, UIScreen.mainScreen().bounds.width, 20.0))
statusBarView.backgroundColor = UIColor.redColor()
view.addSubview(statusBarView)
myles
  • 1,681
  • 1
  • 15
  • 27
0

If your app is using a navigation bar, then the status bar color will be changed to match the color of your navigation bar.

Without a navigation bar, you can place a 20 point tall view (e.g. some view filled with a color) behind the status bar and that's the color that will appear to the user.

I found the above information in this article

To do this in swift, maybe do something like:

// make a view tall enough to fit under the status bar
var statusBarView: UIView = UIView(frame: CGRectMake(0.0, 0.0, 320.0, 20.0))

// give it some color
statusBarView.backgroundColor = UIColor.redColor()

// and add it to your view controller's view
view.addSubview(statusBarView) 
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215