0

I added a navigation bar in a view, but the background color of status bar is not the same with my navigation bar. like this: enter image description here

I searched informations on internet, I can find how to change the color of status bar, but I can not find how to change the background color like the color of navigation bar... Could you help to resolve this problem : to set the background color of status bar like color of navigation bar for a view ? Thank you.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user2262304
  • 329
  • 1
  • 3
  • 10
  • You change the barTint color to change the color of the navigation bar. Also, make sure the bar is not translucent. This issue looks more like a translucent thing than the wrong color, but i'm not 100% sure. – A'sa Dickens Apr 14 '16 at 13:58
  • Thank you for your answer, but I want to change the **background color of status bar**, not a navigation bar... I can change the color of navigation bar...but I can not change the **background color of status bar** – user2262304 Apr 14 '16 at 14:06
  • oh the status bar only has like 2 colors, you physically have to put a view behind the status bar in your controller and change the color of that. You can change the status bar color by overriding preferredStatusBarStyle and returning UIStatusBarSyle.(style enum value here). You might be able to set a bar tint... or possibly set a generic tint for your app somewhere but i don't remember. There is no direct way to change the background color of the status bar. – A'sa Dickens Apr 14 '16 at 14:28
  • I think there is no direct way to change the background color of the status bar too... I added a label behind the status bar, but the background color of the part battery is not changed...So, could you give me a clear answer with the code? Thank you very much ! – user2262304 Apr 14 '16 at 14:52
  • did you add a background color to the label ? – A'sa Dickens Apr 14 '16 at 14:54
  • Yes, but the background color of the part battery is not changed.. – user2262304 Apr 14 '16 at 15:18
  • oh you want to change the battery power color ? that, i think, is impossible – A'sa Dickens Apr 14 '16 at 15:20
  • I added a label, after the background color of status is the same with the color of label without background color of the part battery, background color of the part battery is always not changed. – user2262304 Apr 14 '16 at 15:30

2 Answers2

0

You can use:

UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
itechnician
  • 1,645
  • 1
  • 14
  • 24
  • Hello, this is **color of status bar**, it is not **background color of status bar** – user2262304 Apr 14 '16 at 14:21
  • then you can try this: func setStatusBarBackgroundColor(color: UIColor) { guard let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else { return } statusBar.backgroundColor = color } – itechnician Apr 18 '16 at 06:56
0

You can change the color of status bar if you are using the gradient layer.Here is the code just try it and do let me know.

let colorTop =  UIColor(red: 69/255, green: 90/255, blue: 195/255, alpha: 1.0).CGColor
    let colorBottom = UIColor(red: 230/255, green: 44/255, blue: 75/255, alpha: 1.0).CGColor

    let gradientLayer = CAGradientLayer()
    gradientLayer.colors = [ colorTop, colorBottom]
    gradientLayer.locations = [ 0.0, 1.0]
    gradientLayer.frame = CGRectMake(0, -20, 375, 64)

  self.navigationController?.navigationBar.layer.addSublayer(gradientLayer)
Dupinder kaur
  • 188
  • 2
  • 12