1
votes

Is there a simple way to get the visible / drawn rect of a UIImageView's image? The rect needs to be correct for any chosen contentMode and should take masksToBounds into account.

Example1: 100x100 UIImageView with a 200x200 image, masksToBounds = YES and contentMode = BottomLeft should return x=0, y=0 (or 100 depending on the coordinate system), width=100, height=100.

Example2: 100x100 UIImageView with a 200x200 image, masksToBounds = YES and contentMode = Center should return x=50, y=50, width=100, height=100.

Or do I have to calculate it myself depending on the contentMode and masksToBounds settings of the UIImageView? I thought properties on the CALayer of the UIImageView could help me with that, but so far I wasn't able to get the right values.

1

1 Answers

0
votes

After a bunch of research, I'm pretty sure, it's not possible to get that rect. You need to calculate it manually.

You can either make use of the view's contentMode property or use the layer's contentGravity property to determine the way the image was positioned inside the imageView.