cateof
cateof

Reputation: 6758

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?

Upvotes: 1

Views: 62

Answers (1)

Droppy
Droppy

Reputation: 9721

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...

Upvotes: 1

Related Questions