How can I change the image displayed in a UIImageView programmatically?

后端 未结 15 682
孤街浪徒
孤街浪徒 2020-12-07 08:42

I have an IBOutlet to a UIImageView, but when I look at the UIImageView doc, I can\'t see any hints about programmatically changing it

15条回答
  •  离开以前
    2020-12-07 09:03

    Don't forget to call sizeToFit() after you change image if you then use size of UIImageView to set UIScrollView contentSize and/or compute zoom scale

    let image = UIImage(named: "testImage")
    imageView.image = image
    imageView.sizeToFit()
    scrollView.contentSize = imageView.bounds.size
    

提交回复
热议问题