Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Images for different screen size from Assets.xcassets in Xcode 8?

I create different sizes of background image for my Login screen.
I refer to the apple link https://developer.apple.com/ios/human-interface-guidelines/graphics/launch-screen/
But I'm not doing Launch Screen and I just want to add background to Login screen.

I would like to know which is 1x , 2x and 3x ?

enter image description here


Another problem is when I create Image Set, which size of image should be drag to which place. I have no idea of about that. Or do we need only 3 images (in universal row)?
And then , how about for Landscape image? Where should I put this? enter image description here

like image 207
May Phyu Avatar asked May 16 '17 07:05

May Phyu


2 Answers

I would have created the following sizes:

iPhone:

  • @1x - 640 x 1136 (iPhone SE)
  • @2x - 750 x 1334 (iPhone 7, 6S)
  • @3x - 1242 x 2208 (iPhone 7 Plus, iPhone 6S Plus)

iPad:

  • @2x - 2048 x 1536 (iPad Air, Retina iPad 1st & 2nd Generation / 3rd & 4th & Pad Mini 2nd & 3rd Generation)
like image 119
Rashwan L Avatar answered Oct 03 '22 00:10

Rashwan L


Actually, you need to coding for this.

First, you put images in Assets separately with different names.

Second, use following code:

    var backgroundImageName = ""
    switch UIScreen.main.bounds.height {
        case 480:
            //for iPhone4s,
            backgroundImageName = "background_iPhone4s"
            break;
        case 568:
            //iPhone SE, iPhone5, iPhone 5s
            backgroundImageName = "background_iPhone5"
            break;
        case 667:
            //iPhone 6, 6s, 7
            backgroundImageName = "background_iPhone6"
            break;
        case 736:
            //iPhone 6 plus, 6s plus, 7 plus
            backgroundImageName = "background_iPhonePlus"
            break;
        default:
            break;
    }
    backgroundImageView.image = UIImage(named: backgroundImageName)
like image 41
Yun CHEN Avatar answered Oct 03 '22 00:10

Yun CHEN