iOS: load an image from url

前端 未结 9 1399
生来不讨喜
生来不讨喜 2020-12-02 14:06

I need to load an image from a url and set it inside an UIImageView; the problem is that I don\'t know the exact size of the image, then how can I show the image correctly?<

9条回答
  •  青春惊慌失措
    2020-12-02 14:53

    In swift:

    var url = NSURL.URLWithString("http://www.example.com/picture.png")
    var data = NSData(contentsOfURL : url)
    var image = UIImage(data : data)
    image.size // if you need it
    

提交回复
热议问题