Know the real borders of the image in UIImageView

I am using UIImageView to load an image using aspect. Therefore, the image uses the entire surface of the UIImageView. How do I know what are the borders of an image inside a UIImageView?

Thanks in advance

+3
source share
1 answer
CGFloat aspectRatioX = imageView.bounds.size.width/imageView.image.size.width;
CGFloat aspectRatioY = imageView.bounds.size.height/imageView.image.size.height;
if ( aspectRatioX < aspectRatioY )
    imageRect = CGRectMake(0, (imageView.bounds.size.height - aspectRatioX*imageView.image.size.height)*0.5f, imageView.bounds.size.width, aspectRatioX*imageView.image.size.height);
else
    imageRect = CGRectMake((imageView.bounds.size.width - aspectRatioY*imageView.image.size.width)*0.5f, 0, aspectRatioY*imageView.image.size.width, imageView.bounds.size.height);
+5
source

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


All Articles