UIViewContentModeScaleAspectFill extends the scope of UIView

Given that I have a UIImage that has a large frame.

I put this UIImage in a UIImageView *myImageView;

I set the content mode of myImageView to UIViewContentModeScaleAspectFill .

I also set the myImageView frame to (50.50).

However, my UIImage significantly larger than this smaller frame, and for some reason, the image always extends the frame size of myImageView.

How to ensure that the myImageView frame remains constant and does not change from image to image?

Thanks!

+6
source share
2 answers

Is one side of the image the right size (50)? If so, I suspect that your opinion is still the estimated size, but it is not cropped. Try setting clipsToBounds to your UIImageView on YES .

+13
source

I think your imageView is not expanding, but the image is out of the viewing frame, you can prevent this by adding this:

 [yourImageView.layer setClipsToBounds:YES]; 
-1
source

Source: https://habr.com/ru/post/956719/


All Articles