How to detect iPhone 5 (widescreen devices)?

前端 未结 24 1260
我寻月下人不归
我寻月下人不归 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:05

    In Swift, iOS 8+ project I like to make an extension on UIScreen, like:

    extension UIScreen {
    
        var isPhone4: Bool {
            return self.nativeBounds.size.height == 960;
        }
    
        var isPhone5: Bool {
            return self.nativeBounds.size.height == 1136;
        }
    
        var isPhone6: Bool {
            return self.nativeBounds.size.height == 1334;
        }
    
        var isPhone6Plus: Bool {
            return self.nativeBounds.size.height == 2208;
        }
    
    }
    

    (NOTE: nativeBounds is in pixels).

    And then the code will be like:

    if UIScreen.mainScreen().isPhone4 {
        // do smth on the smallest screen
    }
    

    So the code makes it clear that this is a check for the main screen, not for the device model.

提交回复
热议问题