Created
October 21, 2012 06:26
-
-
Save samwize/3926123 to your computer and use it in GitHub Desktop.
Convenient class to handle the new iPhone 5 taller screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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