How can I use the image in the title bar of the navigation bar in swift ios

I have a problem's. I want to use the image in the title of the navigation bar, but I get an error. ie "UIImage" is not a subtype of "NSString". See below for the code.

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. } } 

Can anyone suggest? Thanks!

+5
source share
1 answer

Set title to navigationItem titleView

 var image = UIImage(named: "logo.png") self.navigationItem.titleView = UIImageView(image: image) 
+9
source

Source: https://habr.com/ru/post/1206011/


All Articles