Difference between UIImage and UIImageView

后端 未结 8 693
予麋鹿
予麋鹿 2021-01-31 16:24

What is the difference between UIImage and UIImageView? Can someone explain it with an example?

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 16:50

    UIimage is an Object which stores data (Jpg, png...) and UIImageView class which contains UIImage as a property. UIImageView can have multiple UIImages, and UIImage is immutable. That bothered me a long time ago, when you create an image you do:

     var image: UIImageView!
    

    But when you execute that "image" you do

    image.image = UIImage.init(named: "image")
    

    Its really easy, you use UIimageView, to create an image with UIImage. UIImage displays the image, and UIImageView is a container for that UIImage.

提交回复
热议问题