alanwong alanwong - 5 months ago 55
iOS Question

Change the toolbar color

It is working for navigationBar:

var colour =
self.navigationController?.navigationBar.tintColor = colour

But do not work for toolbar:

self.navigationController?.toolbar.tintColor = colour

I searched the internet and stack overflow. No answer is workable for me.
Some people said:

self.toolbar.barTintColor = UIColor.redColor()

It is also not working for me. (value of type 'thisView' has no member 'toolbar')

I want to edit the toolbar color in coding. No change in the storyboard setting. Thanks.

I am working on adding a toolbar under the webview. Like go back, stop, reload.


import UIKit

class ViewController: UIViewController {

@IBOutlet weak var webView: UIWebView!

var colour =

override func viewDidLoad() {
self.navigationController?.navigationBar.tintColor = colour

// problem in here ..........................
self.navigationController?.toolbar.tintColor =

let URL = NSURL(string: "")
webView.loadRequest(NSURLRequest(url: URL! as URL) as URLRequest)

@IBAction func backButton(_ sender: AnyObject) {

@IBAction func nextButton(_ sender: AnyObject) {

@IBAction func refreshButton(_ sender: AnyObject) {

@IBAction func stopbutton(_ sender: AnyObject) {



If you've just got a toolbar that is on a ViewController in Your Storyboard all you need to do is add an IBOutlet to your View Controller and connect the toolbar in the storyboard to that outlet. This code goes in your ViewController

@IBOutlet var toolbar: UIToolbar?

Then, in the storyboard, hold the control button and click drag from View Controller (in the left sidebar) to your toolbar. This will create a connection between the toolbar in the storyboard to the toolbar var in your code. After that connection is made all you need to do is set the barTintColor on that toolbar variable like so:

self.toolbar.barTintColor =