How to detect iPhone 5 (widescreen devices)?

前端 未结 24 1329
我寻月下人不归
我寻月下人不归 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条回答
  •  青春惊慌失措
    2020-11-22 01:19

    We now need to account for iPhone 6 and 6Plus screen sizes. Here's an updated answer

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        //its iPhone. Find out which one?
    
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480)
        {
            // iPhone Classic
        }
        else if(result.height == 568)
        {
            // iPhone 5
        }
        else if(result.height == 667)
        {
            // iPhone 6
        }
       else if(result.height == 736)
        {
            // iPhone 6 Plus
        }
    }
    else
    {
         //its iPad
    }
    

    Some useful info

    iPhone 6 Plus   736x414 points  2208x1242 pixels    3x scale    1920x1080 physical pixels   401 physical ppi    5.5"
    iPhone 6        667x375 points  1334x750 pixels     2x scale    1334x750 physical pixels    326 physical ppi    4.7"
    iPhone 5        568x320 points  1136x640 pixels     2x scale    1136x640 physical pixels    326 physical ppi    4.0"
    iPhone 4        480x320 points  960x640 pixels      2x scale    960x640 physical pixels     326 physical ppi    3.5"
    iPhone 3GS      480x320 points  480x320 pixels      1x scale    480x320 physical pixels     163 physical ppi    3.5"
    

提交回复
热议问题