Code below is not working for me, can anyone help to figure it out what is wrong?
var image = UIImage(named: "10384605_10152519403846670_5189785375955620548_n.jpg") as UIImage
self.navigationController.navigationBar.setBackgroundImage(image , forBarMetrics:UIBarMetrics)
self.navigationController.navigationBar.setBackgroundImage(image,
forBarMetrics: .Default)
In AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
//Image Background Navigation Bar
let navBackgroundImage:UIImage! = UIImage(named: "backgroundNB.png")
UINavigationBar.appearance().setBackgroundImage(navBackgroundImage, forBarMetrics: .Default)
return true
}
In Swift 3:
If you want to add a repeating image in the background you can make this call in AppDelegate > didFinishLaunchingWithOptions:
let image = UIImage(named: "imageNameInAsset")
UINavigationBar.appearance().setBackgroundImage(image, for: .default)
If you want to add an image to the center of the navigation bar you need to do this in the ViewController > viewWillAppear:
let titleView = UIImageView(image: UIImage(named: "imageNameInAsset"))
self.navigationItem.titleView = titleView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With