Skip to content

Instantly share code, notes, and snippets.

@samwize samwize/Device.h
Created Oct 21, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.