Size Classes to distinguish between iPhone 5, 6 and 6 Plus?

北慕城南 提交于 2019-12-06 21:33:44

问题


I was very happy to learn that Size Classes are backward compatible with iOS 7 (in some cases). Now I'm wondering - is there a way to use Size Classes to distinguish between iPhone 5, 6 and 6 Plus?


回答1:


No. Quite the opposite actually, size classes are used to abstract the device away. These are the currently used size class:

compact width, compact height: 3.5", 4", 4.7" iPhones in Landscape mode
compact width, regular height: all currently available iPhones in Portrait
regular width, compact height: 5.5" iPhone in Landscape
regular width, regular height: all currently available iPads regardless of orientation




回答2:


You could try testing against the screen height (or width) eg:

//iphone 5
if UIScreen.main.bounds.size.height == 568.0 {
// your code here
}

iphone screen heights are as follows:

iphone 5 = 568.0

iPhone 6/6s/7 = 667.0

iphone 6/7 plus = 736.0



来源:https://stackoverflow.com/questions/28381273/size-classes-to-distinguish-between-iphone-5-6-and-6-plus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!