1

For example, set the background of iphone 5 to image1 and background of iphone 6 to image2, and a third different image for iphone 6+

How can I achieve this using Interface Builder

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Suhaib
  • 2,031
  • 3
  • 24
  • 36
  • http://stackoverflow.com/q/26028918/3141234 – Alexander Aug 23 '16 at 20:55
  • @AlexanderMomchliov thanks for the link. Would you know if it's possible to set different background images using 'Size Classes' in xcode ? – Suhaib Aug 23 '16 at 20:57
  • Size classes aren't meant to differentiate between devices as your question describes. If you were to use them in your context it would only differentiate iPhone from iPad. – Aaron Aug 23 '16 at 21:02
  • @Aaron, I see. Thank you for clarifying this. I don't know why I keep thinking that size classes can be used to differentiate between different iphone versions. – Suhaib Aug 23 '16 at 21:04

1 Answers1

0

Programmatically you could do something like this (this assumes portrait only):

enum Device {

    case iPhone5
    case iPhone6
    case iPhone6P

    static var sizeClass: Device {

        let screenWidth = UIScreen.mainScreen().bounds.width

        switch screenWidth {
        case _ where screenWidth < 375:
            return .iPhone5
        case 414:
            return iPhone6P
        default:
            return .iPhone6
        }
    } 
}

Then where you set the image:

    switch Device.sizeClass {
    case .iPhone5:
        // set image
    case .iPhone6:
        // set image
    case .iPhone6P:
        // set image
    }
Aaron
  • 6,466
  • 7
  • 37
  • 75