Reputation: 2226
I found a bunch of links on SO that show how to set the navigation bar to an image in Objective-C, but none in swift. The one I did find, didn't help: UINavigationBar setBackgroundImage in AppDelegate with Swift
In the didFinishLaunchingWithOptions
in the AppDelegate
I'm attempting to do this with swift with no avail:
let headerImage = UIImage(named: "header.png")
UINavigationBar.appearance().setBackgroundImage(headerImage, forBarMetrics:.Default)
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default
var navigationVC:UINavigationController = UINavigationController(rootViewController: tableVC)
let frame = UIScreen.mainScreen().bounds
window = UIWindow(frame: frame)
window!.rootViewController = navigationVC
window!.makeKeyAndVisible()
How can I set the navigation bar to an image in swift?
Thanks in advance.
Upvotes: 0
Views: 1943
Reputation: 27620
You are using a retina image but Xcode does not know that because it does not have a file name that contains @2x
.
So if you rename your image to [email protected]
it works.
You might want to consider using an Asset Catalog for your images to avoid things like this.
Upvotes: 2