Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of resolving image sets depending on display size
#import "UIImage+ImageAdditions.h"
@implementation UIImage (ImageAdditions)
+ (NSString *)resolveAdaptiveImageName:(NSString *)nameStem {
CGFloat height = [UIScreen mainScreen].bounds.size.height;
if (height > 568.0f) {
// Oversize @2x will be used for iPhone 6, @3x for iPhone 6+
// iPads... we'll work that out later
if (height > 667.0f) {
return [nameStem stringByAppendingString:@"-oversize@3x"];
} else {
return [nameStem stringByAppendingString:@"-oversize"];
}
};
return nameStem;
}
+ (UIImage *)adaptiveImageNamed:(NSString *)name {
return [self imageNamed:[self resolveAdaptiveImageName:name]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment