Skip to content

Instantly share code, notes, and snippets.

@matteodanelli
Created January 31, 2018 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteodanelli/5bfb2f52c4c06978309deda8b8ae8156 to your computer and use it in GitHub Desktop.
Save matteodanelli/5bfb2f52c4c06978309deda8b8ae8156 to your computer and use it in GitHub Desktop.
Apple device detection_Swift
struct Device {
// iDevice detection code
static let IS_IPAD = UIDevice.current.userInterfaceIdiom == .pad
static let IS_IPHONE = UIDevice.current.userInterfaceIdiom == .phone
static let IS_RETINA = UIScreen.main.scale >= 2.0
static let SCREEN_WIDTH = Int(UIScreen.main.bounds.size.width)
static let SCREEN_HEIGHT = Int(UIScreen.main.bounds.size.height)
static let SCREEN_MAX_LENGTH = Int( max(SCREEN_WIDTH, SCREEN_HEIGHT) )
static let SCREEN_MIN_LENGTH = Int( min(SCREEN_WIDTH, SCREEN_HEIGHT) )
static let IS_IPHONE_4_OR_LESS = IS_IPHONE && SCREEN_MAX_LENGTH < 568
static let IS_IPHONE_5 = IS_IPHONE && SCREEN_MAX_LENGTH == 568
static let IS_IPHONE_6 = IS_IPHONE && SCREEN_MAX_LENGTH == 667
static let IS_IPHONE_6P = IS_IPHONE && SCREEN_MAX_LENGTH == 736
static let IS_IPHONE_X = IS_IPHONE && SCREEN_MAX_LENGTH == 812
}
if (Device.IS_IPHONE_X){
//iPhone X
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment