How to specify size for iPhone 6/7 customised edge-to-edge image?

后端 未结 12 980
死守一世寂寞
死守一世寂寞 2020-11-28 01:59

Say I want a bundled image to take up all available screen width in an iPhone app - for example a banner. I\'d create my_banner.png with width 320px

12条回答
  •  北海茫月
    2020-11-28 02:07

    I am using the following trick as some stuff actually works:

    • Asset Catalog for specific devices
    • Specify images for 1x, 2x on the base of 320x640
    • Specify images for 4 2x and 3x on the base of 320x568 (iPhone 5)
    • Create a new Images set for the iPhone 6 specifically (as this is the only device that makes trouble with edge to edge bindings)
    • Only provide 2x image for iPhone 6 in full resolution (750x1334)

    Declare a constant

    #define IS_IPHONE_6 [[UIScreen mainScreen]nativeBounds].size.width == 750.0 ? true : false
    

    and use it like this:

    UIImage *image = [UIImage imageNamed:@"Default_Image_Name"];
    if(IS_IPHONE_^) {
        image = [UIImage imageNamed:@"Iphone6_Image_Name"];
    }
    

    this might be not the most beautiful solution, but it works, at least as long as apple does not provide a better API for edge to edge bindings.

提交回复
热议问题