Feb 022012
 

I noticed that my thumbnails didn’t look sharp on my Retina display. This makes sense since I was asking my server for 50 pixels when in fact I wanted 100 pixels. But how to encapsulate that?

I made a quick little method to give me my 50 or 100 dimension:

+ (int) thumbnailSize 
{
    return [EnkiUtilities pixelsForRetina:50];
}

This call the pixelForRetina class method:

+ (float) pixelsForRetina:(float) pixels
{
    if ([[UIScreen mainScreen] enki_isRetina]) {
        return pixels * 2;
    } else {
        return pixels;
    }
}

I really don’t like the hardcoded 2 in there, I really should grab scale from somewhere. And here is the UIScreen class category to help me out with the retina/non-retina distinction.

@implementation UIScreen(EnkiScreenRetinaAdditions)
- (BOOL)enki_isRetina {
    return [self respondsToSelector:@selector(displayLinkWithTarget:selector:)] && (self.scale == 2.0);
}
@end

This has been incorporated into the open source EnkiUtils.