I have the image view which has fixed size. But I want to fit every size of image into this without stretching.
I tried this
In method resizeImage, I passed my selected image and size of UIImageView.
func resizeImage(image: UIImage, size: CGSize) -> UIImage {
UIGraphicsBeginImageContext(size)
image.drawInRect(CGRectMake(0, 0, size.width, size.height))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
But this is not working, It is still returning the stretched image.
Please let me know what could be the proper solution.
Thanks
I think what you are looking for is your
UIImageView
'scontentMode
property. Like so:This value will make sure that when you set the view's image, the image will fill the view as much as possible without stretching the image. You could also use
.ScaleAspectFill
to completely fill the view, but then your image will be cropped.