tags:

views:

2114

answers:

3

The image.size attribute of UIImageView gives the size of the original UIImage. I would like to find out the size of the autoscaled image when it is put in the UIImageView (typically smaller than the original).

For example, I have the image set to Aspect Fit. Now I want to know its new height and width on the screen so I can draw accurately on the new scaled image.

Is there any way to do this without figuring it out myself based on the UIImageView size & UIImage original size (basically reverse engineering its scaling)?

+1  A: 

How about just get the UIImageView size from its frame? i.e. imageView.frame?

leonho
image.frame.size is the current size of that view in it's superview's coordinate system, which is *probably* measured in pixels.
A: 

If the frame is filled maintaining the image aspect ratio, the imageview frame will not be the same as the image size.

+1  A: 

Since you've got the image view set to Aspect Fit, you can simply take the height and width of the image view along with the height and width of the original image and calculate the height and width of the scaled image.

That said, the better way of doing this is to have a custom view instead of a UIImageView. Then, draw the image yourself in the custom view. That way you can control every aspect of it.

August