I'm trying to set a UIImage as the background of a UIView. The problem is that if I use colorWithPatternImage the background image repeats for the iPhone 6 (as far as I know it uses de @2x resolution). For the iPhone 6 plus I have no problems because it uses de @3x image but iPhone 4,4s,5,5s and 6 uses the same 2@x image and have differents screen sizes.
I'm using Xcode 6.
I have the same problem and I solved following this post
Basically you can use:
After than use a custom category on UIImage to load from the correct asset based 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.