How to handle image scale on all the available iPhone resolutions?

后端 未结 8 601
悲&欢浪女
悲&欢浪女 2020-11-28 17:06

What sizes would be the best to use for images: background.png, background@2x.png and background@3x.png if we want to use this image for example to cover the full width and

相关标签:
8条回答
  • 2020-11-28 17:59

    I've created category for this:

    + (UIImage *)sizedImageWithName:(NSString *)name {
        UIImage *image;
        if (IS_IPHONE_5) {
            image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h",name]];
            if (!image) {
                image = [UIImage imageNamed:name];
            }
        }
        else if (IS_IPHONE_6) {
            image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-750w",name]];
        }
        else {
            image = [UIImage imageNamed:name];
        }
        return image;
    }
    

    you can take full code here: https://gist.github.com/YGeorge/e0a7fbb479f572b64ba5

    0 讨论(0)
  • 2020-11-28 18:05

    the @2 and @3 is not the real image scaling, but only represent how much real pixel represent one virtual pixel on screen, some sort of hdpi/xhdpi/xxhdpi/blabla from android universe. it only show to system what image should be used for some device screen.

    so if you need to use whole screen image - prepare it dependently of real screen size.

    0 讨论(0)
提交回复
热议问题