Skip to content

Instantly share code, notes, and snippets.

@samwize
Created October 21, 2012 06:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwize/3926123 to your computer and use it in GitHub Desktop.
Save samwize/3926123 to your computer and use it in GitHub Desktop.
Convenient class to handle the new iPhone 5 taller screen
#import <Foundation/Foundation.h>
@interface Device : NSObject
/** Returns true if it is a iPhone/iPod with 4 inch tall screen */
+(BOOL)isScreen4Inch;
@end
@interface UIImage (iPhone568)
+(UIImage*)imageNamedFor568h:(NSString*)imageName;
@end
#import "Device.h"
@implementation Device
+(BOOL)isScreen4Inch {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
return YES;
}
return NO;
}
@end
@implementation UIImage (iPhone568)
+(UIImage*)imageNamedFor568h:(NSString*)imageName {
if ([Device isScreen4Inch]) {
NSString *imageNameFor568h = [NSString stringWithFormat:@"%@-568h.%@", [imageName stringByDeletingPathExtension], [imageName pathExtension]];
return [UIImage imageNamed:imageNameFor568h];
}
return [UIImage imageNamed:imageName];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment