Search code examples
iosuiimageviewuiimagexcode8aspect-ratio

UIImage gets distorted/wrong size in UIImageView


I have two UIImageView with dimension 64 x 16 and two images (@2x):

  • image1 (128 x 32)
  • image2 (80 x 32).

I've placed image1 in imageview1 and image2 in imageview2.

When I run the app, imageview1 looks ok, but imageview2 looks distorted. How to deal with different image sizes? I want the UIImageView size to be fixed (64 x 32).

Any help would be really appreciated


Solution

  • image1 with dimension 128 x 32 and image2 with dimension 80 x 32

    Your 2x image should have 160 x 64, not 128 x 32.

    Edit:

    If you have a 64x16 points of UIImageView, that results in 128 x 32 pixels on a 2x scale screen, if you have an image with 80 x 32 pixels, that will get disorted if you try to put it inside a 64x16 point (128x32 pixels) UIImageView