You can call
setBackgroundImage() on any navigation bar, providing an image to use and the bar metrics you want it to affect, and you're done. Bar metrics left you specify what sizes of bars you want to change: should this by all bars, just phone-sized bars, or just phone-sized bars on landscape?
Here's an example that changes the navigation bar background image to a file called "navbar-background.png" (you'll want to change that!) across all device sizes:
let img = UIImage(named: "navbar-background") navigationController?.navigationBar.setBackgroundImage(img, for: .default)
Sponsored You’re already busy updating your app for Swift 4.2 and iOS 12, so why not let Instabug help you find and fix bugs? Add just two lines of code to your project and receive comprehensive reports with all the feedback you need to ship a world-class app – click here to learn more!
Available from iOS 5.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.
Want to build macOS apps?
Hacking with macOS delivers 18 awesome projects that teach you macOS development in no time – take control of your desktop today!