1

How can I change the color of the header section (status bar) in an iPhone App. The part with the carrier, time, and battery.

This part

enter image description here

More specifically, this part. I'd like to change the UI from black, to white or an easier to see color.

enter image description here

Rashwan L
  • 35,847
  • 7
  • 90
  • 97
Trevor Wood
  • 1,805
  • 1
  • 24
  • 42
  • 1
    Do you want to change the color of the text "Carrier" and the time, etc. or the background color of the status bar? – rmaddy Sep 15 '16 at 16:14
  • @rmaddy the text part, also knowing how to change just the background would be helpful too. – Trevor Wood Sep 15 '16 at 16:15

1 Answers1

6

To change the navigation bar color:

navigationController!.navigationBar.barTintColor = UIColor.blueColor()

To change the text in the navigation bar:

navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.yellowColor()]

Update
To change the status bar:

  1. Go to your info.plist and add the following key View controller-based status bar appearance and set the value to NO
  2. In you viewControllers viewDidload do set

White bar:
UIApplication.sharedApplication().statusBarStyle = .LightContent

Dark bar:
UIApplication.sharedApplication().statusBarStyle = .Default

Rashwan L
  • 35,847
  • 7
  • 90
  • 97
  • Hey Rashwan, thanks so much for the help. So I'm kind of a newbie here. Where should I place this code? and do i need to link anything up to it? – Trevor Wood Sep 15 '16 at 16:23
  • 1
    Just add it in your `viewDidLoad` function @TrevorWood – Rashwan L Sep 15 '16 at 16:24
  • I just put the code in there and this error came out... It's kind of long so I put it in my OP – Trevor Wood Sep 15 '16 at 16:31
  • 1
    Are you sure it´s because of the code above? I have created a [test project](https://drive.google.com/file/d/0B2TR9xoKqvZNa0Zzc2l2M0RocTQ/view?usp=sharing) for you that changes the navbar color and also the text. Take a look at it and see if you have done it like this. – Rashwan L Sep 15 '16 at 16:41
  • yes I just made a completely new project and got this error `fatal error: unexpectedly found nil while unwrapping an Optional value` Do I need to link anything up? I'll have a look at your example – Trevor Wood Sep 15 '16 at 17:09
  • ohhh, no I meant something different. I will post a new picture of what I'm trying to change – Trevor Wood Sep 15 '16 at 17:13
  • 1
    So you want to change the status bar. You can either have it white or black, check the update of how to change the color @TrevorWood – Rashwan L Sep 15 '16 at 17:47