NEW: Master Swift design patterns with my latest book! >>

How to set a custom title view in a UINavigationBar

Written by Paul Hudson    @twostraws

Each view controller has a navigationItem property that dictates how it customizes the navigation bar if it is viewed inside a navigation controller. This is where you add left and right bar button items, for example, but also where you can set a title view: any UIView subclass that is used in place of the title text in the navigation bar.

For example, if you wanted to show an image of your logo rather than just some text you would use this:

navigationItem.titleView = UIImageView(image: UIImage(named: "logo"))

Available from iOS 2.0

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Hacking with watchOS

Transfer your Swift skills to watchOS the easy way, and learn to build real-world apps in the process!

Click here to visit the Hacking with Swift store >>