How to stop an image from stretching within a UIImageView?
Use the contentMode
property. You probably want either UIViewContentModeScaleAspectFit
or UIViewContentModeCenter
.
Setting clipsToBounds in combination with UIViewContentModeScaleAspectFit contentMode was what did the trick for me. Hope that helps someone!
imageView.clipsToBounds = YES;
imageView.contentMode = UIViewContentModeScaleAspectFit;
You can use
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
Swift 3:
imageView.contentMode = .scaleAspectFit
Or UIViewContentModeCenter
/ .center
, or any of the other modes described in the UIView documentation.
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.