-
-
Save falcon11/43e05dbd56bd8fcb348ac89f523327dd to your computer and use it in GitHub Desktop.
iPhone X and other iOS device detection by Swift and Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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