Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can use image in navigation bar title in swift ios

i'm in trouble. i want to use image in navigation bar title, but i'm getting a error i.e "UIImage" is not a subtype of "NSString". Below the code, look it.

class Dashboard: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.title = UIImage(named: "logo.png")        
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

Anyone can suggest? Thanks!

like image 229
Viju Avatar asked Nov 01 '14 15:11

Viju


1 Answers

Set the navigationItem's titleView

var image = UIImage(named: "logo.png")
self.navigationItem.titleView = UIImageView(image: image)
like image 150
Glynbeard Avatar answered Sep 28 '22 15:09

Glynbeard