I have a UIImageView
where I have set the frame size to x = 0, y = 0, width = 404, height = 712
.
In my project, I need to change the image in
Change the UIImage's Mode from 'scale to fill' to 'Center' within the interface builder. Make sure your image is the exact size you need.
How to use original size of image - without any stretching
scale to fill
to Aspect Fit
within the interface builder.still stretch when image is bigger than imageivew
swift
let qCodeImage = UIImage(named: "qcode-placeholder.png")!
let qCodeImageView = UIImageView(frame: CGRectMake(0, 0, CGRectGetWidth(cardView.frame)-30, CGRectGetWidth(cardView.frame)-30))
qCodeImageView.image = qCodeImage
qCodeImageView.clipsToBounds = true
qCodeImageView.contentMode = UIViewContentMode.ScaleToFill
qCodeImageView.center = cardView.center
Change the contentMode, e.g.:
imageView.contentMode = UIViewContentModeScaleAspectFit;