Tutorial – Set Navigation Bar Color
You can simply set the Navigation Bar Color in XCode using one line of code.
I have setup a XCode project with a simple navigation controller as the root view controller of the default view. It looks like:
To set the navigation bar color simply add the following line of code in viewDidLoad()
override func viewDidLoad() { super.viewDidLoad() self.navigationController?.navigationBar.barTintColor = UIColor.redColor() }
If you run the app you will now see the Navigation Bar has a red color to it:
To set it to a custom color use the RGB code as follows, replacing the 100 with your relevant RGB codes.
override func viewDidLoad() { super.viewDidLoad() self.navigationController?.navigationBar.barTintColor = UIColor(red: 100/255, green: 100/255, blue: 100/255, alpha: 1) }
The above line of code sets it to gray using the RGB colors as follows: