How can I detect iPhone X’s screen size?

How can I detect iPhone X’s screen size?

After Apple released iPhone X I am trying to update my application for iPhone X. The UI elements to fit iPhone X I have to detect the screen size of iPhone X and I found the code below which works for me.

if UIDevice().userInterfaceIdiom == .phone {
        switch UIScreen.main.nativeBounds.height {
        case 1136:
            print("iPhone 5 or 5S or 5C")
        case 1334:
            print("iPhone 6/6S/7/8")
        case 2208:
            print("iPhone 6+/6S+/7+/8+")
        case 2436:
            print("iPhone X")
        default:
            print("unknown")
        }
    }

Leave a Reply