Xernox Xernox - 1 year ago 68
iOS Question

How to choose 1 UIImage size for all iPhone resolutions?

What image size should I choose if I can (at the moment) add only one image size?
Images will be used in

, most likely width will be from edge to edge, while height may vary.

So should I add 1242px width images and then app itself would downscale it to 750/640px? Or should I use 750px, because there are more iPhone 6 users than 6+ and more users will have better looking image (in other words more people will see original image, rather than scaled)?

Answer Source

Use 1242px image and downscale it. To get the best possible image quality set yourUIImageView.layer.minificationFilter = kCAFilterTrilinear. You wont see any difference in the image quality when using trilinear filtering.

Another options is to downscale the image before using it:

extension UIImage {
  public func rescale(width: CGFloat, _ height: CGFloat) -> UIImage {
    let newSize = CGSizeMake(width, height)

    UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
    drawInRect(CGRectMake(0.0, 0.0, newSize.width, newSize.height))
    let scaledImage = UIGraphicsGetImageFromCurrentImageContext()

    return scaledImage

let myImage = UIImage(named: "myimage").rescale(newWidth, newHeight)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download