Search code examples
iphoneiosuiimagescaleretina-display

How to downscale retina image loaded from remote server for non retina iPhones?


I have to load icons for my app from a remote source, the images are 50x50px to be displayed on the devices at 25x25px.

At the moment the icons are showing the correct size on retina devices but twice the size on non retina devices.

FYI: There is no way for the remote source to supply non retina images.

How can I scale-down the UIImage on non-retina devices, so that all devices display the same size?


Solution

  • First check if you have Retina display

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){
    

    then you'll need to set the scale option of the image:

    UIImage * scaledImage = [UIImage alloc];
    scaledImage = [[scaledImage initWithCGImage:[resourceImage CGImage] scale:2.0 orientation:UIImageOrientationUp] autorelease];
    

    Then i believe the imageView should scale it and display correctly