IOS image for iphone 6

I am trying to set UIImage as UIView background. The problem is that if I use colorWithPatternImage the background image is repeated for iPhone 6 (it uses @ 2x resolution as far as I know). For iPhone 6 plus, I have no problem because it uses de @ 3x image, but iPhone 4,4s, 5,5s and 6 use the same 2 @x image and have different screen sizes.

I am using Xcode 6.

+3


source to share


1 answer


I have the same problem and I solved after this post

Basically you can use:

  • one image set for 1x, 2x and R4. This covers iPhone 4, 4S and 5 / 5S / 5C, as well as iPads, scaling the app from the iPhone 4 layout.
  • image "xxxxx-oversize" for iPhone 6
  • "xxxxx-overize @ 3x" for iPhone 6 Plus


enter image description here

After using custom category in UIImage to load from 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

      

+4


source







All Articles