1

I have a UIImageView (in UITableViewCell) which gets image from URL. Obviously, it takes some time to load image from the URL.

I want to get the image size after the image finished loading and set the cell height to the height of image. But I cant get the image height after its loaded and all constraints are applied.

Please help.

Narendra Ojha
  • 673
  • 8
  • 18

1 Answers1

0

I would suggest that you look at Alamofire (here) and the AlamofireImage (here) libraries. They are great a asynchronously loading images. There are many great tutorials available on how to use them optimally in a tableview and even an 'alamofireimage' tag on stack overflow.

In short, this is how you would download the image:

let imageView = UIImageView(frame: frame)

let URL = NSURL(string: "https://httpbin.org/image/png")!

imageView.af_setImageWithURL(URL)

In order to set the size of the cell, you would need to use auto layout constraints (see this question).

Community
  • 1
  • 1
The Hexagon
  • 128
  • 1
  • 9