How To Change Navigation Bar Color iOS Swift 5

Next Story

How to repeat a string in Swift 4

Sometimes you will want to change the color of your navigation bar for branding purposes, and it is actually pretty easy to do.

Use the following snippet in your view controller in viewDidLoad to change the color you would like.


// get the navigation bar from the current navigation controller if there is one
let navBar = self.navigationController?.navigationBar

// change the bar tint color to change what the color of the bar itself looks like
navBar?.barTintColor = UIColor.gray

// tint color changes the color of the nav item colors eg. the back button
navBar?.tintColor = UIColor.white

// if you notice that your nav bar color is off by a bit, sometimes you will have to
// change it to not translucent to get correct color
navBar?.isTranslucent = false

// the following attribute changes the title color
navBar?.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

I hope you enjoyed this snippet and you are able to customize the UIColor’s to any color that you wish.

Leave a Reply

Your email address will not be published. Required fields are marked *

https://www.googletagmanager.com/gtag/js?id=UA-63695651-4