Snorlax
Snorlax

Reputation: 4765

Photo Picker, after picking, image is too big

I predefined the image's size in attributes of 320 320[and gave it a aspect ratio constraint of 1:1

enter image description here
After I click the photo and select an image from the photo library: enter image description here

What things should I be checking to make the photo stay in its 320 by 320 container?

Upvotes: 1

Views: 352

Answers (5)

Gaurav Patel
Gaurav Patel

Reputation: 532

photo.contentMode = UIViewContentModeScaleAspectFill;
[photo setClipsToBounds:YES];

Upvotes: 1

Pranav Wadhwa
Pranav Wadhwa

Reputation: 7746

Say this

imagePickerController.allowsEditing = true

Then you will have the option to crop the image to have it fit

Upvotes: 0

GetSwifty
GetSwifty

Reputation: 7756

FYI, you don't really not both height/width and aspect ratio.

The two thing you will likely need to look at changing are the contentMode, and clipsToBounds

Upvotes: 0

Julien Quere
Julien Quere

Reputation: 2459

I think you should set the contentMode of your UIImageView to UIViewContentModeScaleAspectFit.

You can do it in the code, or in Interface Builder (set the mode to Aspect fit): How to set imageview mode

If you want, you can read the Apple's doc: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/ (on Understanding How Images Are Scaled)

Upvotes: 0

123FLO321
123FLO321

Reputation: 862

Try calling:

view.updateConstraintsIfNeeded()

after loading the image.

Upvotes: 0

Related Questions