MegaManX MegaManX - 1 year ago 52
iOS Question

Using an image as a background of a UIViewController and supporting multiple screen sizes

On some view controllers I am using images as background for the whole screen. I was wondering what is the best practice for this, since I want to support all currently available iPhones (5-7). Normally for images I would get @2x and @3x image, but here the case is a little bit different?

Do I add 4 photos to app and then ask system on which device i am running and than load appropriate photo? This seems kinda clunky, an not really elegant.

Answer Source

You don't really have that many options.

You could bundle different images for the different device aspect ratios, check the device aspect ratio at runtime, and load the correct image. This implementation is flawed, as it doesn't account for future device aspect ratios. You could have a webservice which returns a correct image for a given aspect ratio, to take that work off of the client.

You could also create a single image that looks good on all device sizes, and load the image into a UIImageView and set its contentMode UIViewContentMode.scaleAspectFill to fill the entire image into the view's frame, cropping some portion of the top, bottom, or sides out.