How to detect iPhone 5 (widescreen devices)?

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

    I used hfossli's answer and translated it to Swift

    let IS_IPAD = UIDevice.currentDevice().userInterfaceIdiom == .Pad
    let IS_IPHONE = UIDevice.currentDevice().userInterfaceIdiom == .Phone
    let IS_RETINA = UIScreen.mainScreen().scale >= 2.0
    
    let SCREEN_WIDTH = UIScreen.mainScreen().bounds.size.width
    let SCREEN_HEIGHT = UIScreen.mainScreen().bounds.size.height
    let SCREEN_MAX_LENGTH = max(SCREEN_WIDTH, SCREEN_HEIGHT)
    let SCREEN_MIN_LENGTH = min(SCREEN_WIDTH, SCREEN_HEIGHT)
    
    let IS_IPHONE_4_OR_LESS = (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
    let IS_IPHONE_5 = (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
    let IS_IPHONE_6 = (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
    let IS_IPHONE_6P = (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
    

提交回复
热议问题