Scaling a UIImage to appear properly in a UIImageView

So I'm progromatically creating a UIImageView and adding a UIImage to it. This works except that it looks like the image is full size so I'm only seeing a tiny part of the image through the UIImageView. What's the best way to make the UIImage appear properly?


Here's what I have so far:


let imageView = UIImageView(image: myImg)
imageView.contentMode = .scaleAspectFit
imageView.clipToBounds = true


Thanks!

Answered by n0kx in 203801022

I got it to work by initializing the UIImageView with a frame using the cell's contentView bounds.


let imageView = UIImageView(frame: cell.contentView.bounds)
imageView.image = myImg
cell.contentMode = .scaleAspectFit
cell.clipToBounds = true
cell.addSubview(imageView)

What is your entire view controller hierarchy, starting with the root view controller?

Scaling a UIImage to appear properly in a UIImageView
 
 
Q