How to handle image scale on all the available iPhone resolutions?

You don’t have to have each image in all scales if it won’t be used. Make only the sizes you need and name them according to their width. For portrait full-device-width images, you need 320px wide at 1x and 2x, 375px wide at 2x and 414px wide at 3x.

4″ devices used “-568h” suffix for naming their launch images, so I’d recommend a similar naming scheme:

  • ImageName-320w (@1x & @2x)
  • ImageName-375w (@2x)
  • ImageName-414w (@3x)

Then figure out what image you need at runtime:

NSNumber *screenWidth = @([UIScreen mainScreen].bounds.size.width);
NSString *imageName = [NSString stringWithFormat:@"name-%@w", screenWidth];
UIImage *image = [UIImage imageNamed:imageName];

This might break if other widths are added in future, but so far Apple has always required rebuilding the app to support new displays so I guess it’s somewhat safe to assume they will continue doing that.

Leave a Comment