How to detect the screen size of iPhone 5?

iOSMobile DevelopmentiPhone/iPad

Detecting screen size of an apple device is an easy and simple task. The UIKIT module of iOS SDK provides many functions and classes that deal with user interface, screen sizes and many other UI elements.

One of them is UIScreen which deals with the device screen.

UIScreen.main provides the current main screen of the device in use, which further has methods that return other features and properties of the current screen.

To find if the current screen is an iPhone 5 or not, we’ll first have to find the current size of the screen and compare with a value. The height of an iPhone 5 is 568 points.

Step 1 − Getting the height of current screen

let height = UIScreen.main.bounds.height

Step 2 − Comparing the height

if height == 568 {
   print("this is an iPhone 5 screen")
}else {
   print("this is some other screen - the size is \( height )")

This method can be further extended to see different screen sizes and compare other iPhone screen sizes. This can be converted as a function like,

func checkIphone() -> Bool {
   if height == 568 {
      return true
   }else {
      return false

This is the result of above code when run on an iPhone 7 plus simulator.

Published on 28-Dec-2018 15:00:10