1

I want the status bar to have a darker tone than the navigation bar? how can i implement this in Swift 2.0 in IOS 9 An exmaple is as attached:enter image description here

I am able to turn the status bars text to white but not the background to a darker tone then the navigation bar? Would i need to a add a separate view over it? And if so how because i cant get it on top of the navigation bar?

Minhal Khan
  • 261
  • 3
  • 10
  • 1
    This could help you, http://stackoverflow.com/questions/26956728/changing-the-status-bar-color-for-specific-viewcontrollers-using-swift-in-ios8 – Santosh Jul 26 '16 at 14:44
  • Your not understanding my problem, i already know how to change the status bar text to light i need to change the background colour which is different from the navigation background – Minhal Khan Jul 26 '16 at 15:02
  • Well what's the code that you've tried? – Dershowitz123 Jul 26 '16 at 15:44
  • I havnt tried to change the background because i cant find a way, i just know how to change the status bar colour to whi9te through the attributes inspecotr – Minhal Khan Jul 26 '16 at 15:52
  • for Xcode 8.1 :- http://stackoverflow.com/questions/36207499/set-the-status-bar-to-black-colour/41124747#41124747 – Shrawan Dec 13 '16 at 15:29

2 Answers2

2

Answer:

let view = UIView(frame: CGRectMake(0, 0, 500, 20))
view.backgroundColor = UIColor.redColor()
self.navigationController?.view.addSubview(view)
Minhal Khan
  • 261
  • 3
  • 10
0

You just need to add a new UIView and set it to the appropriate colour. Either give it a frame or add constraints so it sits at the top.

Its height should be the height of the status bar (which is usually 20 I believe but you can get this programatically as well just incase it changes...or isn't present.)

UIApplication.sharedApplication().statusBarFrame.size.height
Hodson
  • 3,003
  • 1
  • 17
  • 44
  • Tried but i cant get it to go over the navigation bar? – Minhal Khan Jul 26 '16 at 19:15
  • 1
    Even if you set the frame as such: `let view = UIView(frame: CGRectMake(0, 0, 500, 20))` it still doesn't show above the navigation bar? Note: 500 if too much for width, you should set that to the actual screen width but for quickness, I just set it to a large number (bigger than the screen width). – Hodson Jul 27 '16 at 07:23
  • THANK YOU! But to add if anyone else has the problem, run this: – Minhal Khan Jul 27 '16 at 19:22
  • `view.layer.zPosition = 100` can help if it's not showing – David Lawson Jul 03 '18 at 02:23