1

I wonder if its possible to check if the user is using an iphone 5 or iphone 6 using size class?

I have a header image that I want to make larger when the user is using an iphone 6 instead of iphone 5.

Right now I am using this library to check what device.

And I do so by adding this in viewDidLoad

if device == .iPhone5 || device == .iPhone5s || device == .iPhone5c {
    //Update image size constraints etc
   view.layoutIfNeeded()
} 

But is it possible to use size class only?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2636197
  • 3,982
  • 9
  • 48
  • 69

1 Answers1

2

Only iphone 6 plus has different size class (regular class at landscape). You can't distinguish between iphone 5 and 6 using size class.

You can use viewWillTransitionToSize and check screen size to determine the device. Alternatively, you can use the following variables:

[[UIScreen mainScreen] bounds].size.height
[[UIScreen mainScreen] bounds].size.width

(SOURCE) In instances where two devices with equal screen sizes but different resolutions exist, the scaling factor of resolution could be used to discern which device you're dealing with. (DOCS)

float scaleFactor = [[UIScreen mainScreen] scale];
Community
  • 1
  • 1
stefos
  • 1,235
  • 1
  • 10
  • 18