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

后端 未结 12 1011
死守一世寂寞
死守一世寂寞 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:31

    I couldn't find a way to do it either, as I had a background Image that was perfectly sized with the Asset Catalog on every device except the iPhone 6. My fix (I did this in SpriteKit)?

    if (bgNode.size.width != self.frame.size.width) {
            bgNode.texture = [SKTexture textureWithImageNamed:@"i6bg.png"];
            [bgNode runAction:[SKAction scaleXTo:self.frame.size.width/bgNode.size.width y:self.frame.size.width/bgNode.size.height duration:.1]];
        }
    

    bgNode is the background image that is pulled up by the device. If it's an iPhone 6, it won't fit the screen and so the background image width wont be the same as the screen width. When the device is recognized as an iPhone 6, I change the texture to the R4 texture (the @2x for retina) and scale it to the correct dimensions.

    I tried doing the same with the regular @2x image, but the scaled image looked very bad (it was too stretched out and noticable). With the R4 texture scaled, the proportions of width/height are a bit better and so the change isn't even noticeable. I hope this gives you some idea as to what you can do before Apple adds an iPhone 6 Asset.

提交回复
热议问题