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

后端 未结 8 639
悲&欢浪女
悲&欢浪女 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:45

    i think we should use different size of background images for different devices. Just use @3x scale images for background.

    You can detect device with below lines.

    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    #define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
    
    #define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
    #define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
    #define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
    #define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
    
    #define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
    #define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
    #define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
    #define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0) 
    

提交回复
热议问题