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.
}
}
有人可以建议吗?谢谢!
答案 0 :(得分:9)
设置navigationItem的titleView
var image = UIImage(named: "logo.png")
self.navigationItem.titleView = UIImageView(image: image)
答案 1 :(得分:0)
为我工作
let image : UIImage = UIImage(named: "headerLogo")
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
imageView.contentMode = .scaleAspectFit
imageView.image = image
navigationItem.titleView = imageView
答案 2 :(得分:0)
Swift 5+,iOS 13+
navigationItem.titleView = UIImageView(image: UIImage(named: "id_logo"))