0

We are currently building an IOS app, part of the functionality involves importing images from an external CMS to be displayed in a news feed. We need to make all images conform to retina standard but aren't quite sure how to go about this.

For example - we have a placeholder which is 300px x 150px as part of a uitableviewcontroller's custom cell - so in my understanding we need both 600px x 300px and 300 x 150px versions of the images available to deque for retina/non-retina devices.

My question is how do we allow the device to select the relevant image? I guess we download image.png and image@2x.png in the respective sizes - but how would we apply the relevant image in the following statement?

 cellA.ArtImg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:TheImageWithURL]]];

Does the image need to be converted into an Xcasset? Or can the relevant size be selected somehow?

Dancer
  • 17,035
  • 38
  • 129
  • 206

1 Answers1

1

If you are developing an app for both retina device only, just download 600px x 300px image and set it to your imageView as like below.

Also No need to download the two versions of images.

 cellA.ArtImg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:TheImageWithURL]]];

If you are developing an app for both retina and non-retina device, let's check the device type while downloading.

Example :

#define DEVICE_ISRETINA   ([[UIScreen mainScreen] scale] > 1)

cellA.ArtImg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:(DEVICE_ISRETINA)?TheRetianImageURL:TheNonRetinaImageURL]]];
Natarajan
  • 3,241
  • 3
  • 17
  • 34