我如何在swift ios中使用导航栏标题中的图像

Vij*_*iju 5 uinavigationbar ios swift

我有麻烦了.我想在导航栏标题中使用图像,但我收到一个错误,即"UIImage"不是"NSString"的子类型.在代码下面,看看它.

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

}
Run Code Online (Sandbox Code Playgroud)

有人可以建议吗?谢谢!

Gly*_*ard 9

设置navigationItem的titleView

var image = UIImage(named: "logo.png")
self.navigationItem.titleView = UIImageView(image: image)
Run Code Online (Sandbox Code Playgroud)