0
votes

I have a UIImageView in cell with default image and size 80x80 and constraints. Then in table view i dynamically load new images with different sizes:

if let url = NSURL(string: currentStoreProduct.productImageUrl) {
                if let data = NSData(contentsOfURL: url) {
                    cell.imageView!.image = UIImage(data: data)
                }
            }

But when i set this images to my imageView, the images do not fit size of previous. I want to scale this images to current width and height of default image. I tried this:

cell.imageView!.frame = CGRectMake(cell.imageView!.frame.origin.x, cell.imageView!.frame.origin.y, 80, 80)

But it doesn't help.

1
If you have constraints on the image view then you need to resize it by editing the constraints. If you change the frame it will get overwritten by the values from the constraints on the next layout pass. - dan

1 Answers

0
votes

I believe you should try

imageView.clipsToBounds = true
imageView.contentMode = UIViewContentMode.ScaleToFill

the second one could be different (it depends on your needs), you can use .ScaleAspectFit, .ScaleAspectFill and so on