Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scale the image to fit the image view in ios?

Tags:

ios

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. Here is my screen shot.

like image 758
jerry_sjtu Avatar asked Oct 08 '14 01:10

jerry_sjtu


People also ask

How do I scale an image in Xcode?

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.

How do I resize an image in swift 5?

Image resize function in swift as below. func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage { let size = image. size let widthRatio = targetSize. width / size.


2 Answers

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.

UIImageView Content Mode

like image 128
Mike S Avatar answered Oct 08 '22 21:10

Mike S


A couple of methods to play with:

imageView.contentMode = UIViewContentMode.ScaleAspectFill
imageView.contentMode = UIViewContentMode.ScaleAspectFit
like image 41
Steve Rosenberg Avatar answered Oct 08 '22 21:10

Steve Rosenberg