How to detect iPhone 5 (widescreen devices)?

前端 未结 24 1332
我寻月下人不归
我寻月下人不归 2020-11-22 00:50

I\'ve just upgraded to XCode 4.5 GM and found out that you can now apply the \'4\" Retina\' size to your view controller in the storyboard.

Now if I want to create a

24条回答
  •  旧时难觅i
    2020-11-22 01:16

    In Swift 3 you can use my simple class KRDeviceType.

    https://github.com/ulian-onua/KRDeviceType

    It well documented and supports operators ==, >=, <=.

    For example to detect if device has bounds of iPhone 6/6s/7, you can just use next comparison:

    if KRDeviceType() == .iPhone6 {
    // Perform appropiate operations
    }
    

    To detect if device has bounds of iPhone 5/5S/SE or earlier (iPhone 4s) you can use next comparison:

    if KRDeviceType() <= .iPhone5 {   //iPhone 5/5s/SE of iPhone 4s
    // Perform appropiate operations (for example, set up constraints for those old devices)
    }
    

提交回复
热议问题