---
title: "#72: Customizing Navigation Bars 🍀"
url: https://littlebitesofcocoa.com/72-customizing-navigation-bars
author: Jake Marsh
published: 2015-09-01
topics: ["UIKit","Appearance"]
description: "Navigation Bars are a versatile part of iOS. Let's take a look at some different ways we can customize their appearance and behavior."
---

# #72: Customizing Navigation Bars 🍀

By Jake Marsh, September 1, 2015. HTML: https://littlebitesofcocoa.com/72-customizing-navigation-bars

**Navigation Bars** are a versatile part of iOS. Let's take a look at some different ways we can customize their appearance and behavior.

## Custom Fonts and Colors

``` swift
let nba = UINavigationBar.appearance()
let bba = UIBarButtonItem.appearance()

let titleTextAttributes = [ NSFontAttributeName : navBarFont ]

nba.barTintColor = green
nba.tintColor = darkGreen
nba.titleTextAttributes = titleTextAttributes

bba.setTitleTextAttributes(titleTextAttributes, forState: .Normal)
```

<img src="https://media.littlebitesofcocoa.com/bite-assets/072-customizing-navigation-bars-1.png" style="max-width: 281px;" />

## Hide/Show Navigation Bar when Scrolling

``` swift
navigationController?.hidesBarsOnSwipe = true
```

This will cause our **navigation bar** to slide on and off screen as the user scrolls, just like in Safari for iOS.

## Empty Back Button

We want a **back button** with no text. We _could_ set the **title** of our first **view controller** to an empty string, but then our first **view controller** would be title-less. We can get the best of both worlds by giving the first **view controller** a custom **back button item** with an empty title. We'll need to do this _before_ we push on a new **view controller**.

``` swift
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
```

<img src="https://media.littlebitesofcocoa.com/bite-assets/072-customizing-navigation-bars-2.png" style="max-width: 281px;" />

## Use an Image as a Title

``` swift
let imageView = UIImageView(image: UIImage(named: "app-logo")!)
navigationItem.titleView = imageView
```

<img src="https://media.littlebitesofcocoa.com/bite-assets/072-customizing-navigation-bars-3.png" style="max-width: 281px;" />
