Search code examples
iosios7retina-display

Code for retina displays in iOS


We are coding in iOS 7.x and I came to the following code snippet:

if ( condition ) {
  if (UIScreen.mainScreen.scale > 1) {  
            self.canvas.image = [myImage imageScaledToFitSize:CGSizeMake(30,30)];             
       } else { 
            self.canvas.image = [myImage imageScaledToFitSize:CGSizeMake(60,60)];       
        }
}

Is this the proper way to code? If this "retina" check is the way to go, then it should be placed everywhere in the code.

If this UIScreen.mainScreen.scale is not correct, could you please point the correct way to go for retina/non-retina display handling?


Solution

  • Seems a bit hardcoded; better would be:

    if ( condition ) {
        CGFloat scale = UIScreen.mainScreen.scale;
        self.canvas.image = [myImage imageScaledToFitSize:CGSizeMake(60.0 / scale, 60.0 / scale)];
    }
    

    However it's not clear to me what the 60 signifies...