In my iphone app i need to set image in the image view.
the image view height is always 100pixels.
we need to set the width of the image view with respect to the original image scale ratio.
ie per suppose width X height of an image is 300×400 (original) (4×3)
our displayed image view image size would be 75X100
width X height of an image is 512×512 (original) (1×1)
our displayed image view image size would be 100X100
width X height of an image is 128 x 256 (original) (1×2)
our displayed image view image size would be 50X100
in all those cases image view height 100pixel should be same, but the width need to varie with respect to the image ratio.
And finally the image view should be in center of the view
How to achieve it
There are a couple of ways you can achieve this. The simplest is to set the scaling mode on the image view to Aspect Fill in Interface Builder, or
The second way is to calculate the aspect ratio of the image and set the width. Something like: