I put an image in an image view in xcode and set "scale to fit" mode, but I find that the image doesn't fit the size of the image view. So how can I make the image to fit the size of the image view in ios?
Below is the screenshot of storyboard.
To get the native size of the image just select the image and press Command + = on the keyboard. the to re-size it proportionally select the corner and hold down the shift key when you re-size it.
Image resize function in swift as below. func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage { let size = image. size let widthRatio = targetSize. width / size.
To do this in your storyboard, select your UIImageView
, open the Attributes Inspector, and select either "Aspect Fill" or "Aspect Fit" from the "Mode" drop down menu.
A couple of methods to play with:
imageView.contentMode = UIViewContentMode.ScaleAspectFill
imageView.contentMode = UIViewContentMode.ScaleAspectFit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With