Created
May 14, 2020 11:20
-
-
Save multitudes/0e24228fdb20032d2517c1cf37dee33a to your computer and use it in GitHub Desktop.
DeviceType and ScreenSize for iPhone's
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
enum ScreenSize { | |
static let width = UIScreen.main.bounds.size.width | |
static let height = UIScreen.main.bounds.size.height | |
static let maxLength = max(ScreenSize.width, ScreenSize.height) | |
static let minLength = min(ScreenSize.width, ScreenSize.height) | |
} | |
enum DeviceType { | |
static let idiom = UIDevice.current.userInterfaceIdiom | |
static let nativeScale = UIScreen.main.nativeScale | |
static let scale = UIScreen.main.scale | |
static let isiPhoneSE = idiom == .phone && ScreenSize.maxLength == 568.0 | |
static let isiPhone8Standard = idiom == .phone && ScreenSize.maxLength == 667.0 && nativeScale == scale | |
static let isiPhone8Zoomed = idiom == .phone && ScreenSize.maxLength == 667.0 && nativeScale > scale | |
static let isiPhone8PlusStandard = idiom == .phone && ScreenSize.maxLength == 736.0 | |
static let isiPhone8PlusZoomed = idiom == .phone && ScreenSize.maxLength == 736.0 && nativeScale < scale | |
static let isiPhoneX = idiom == .phone && ScreenSize.maxLength == 812.0 | |
static let isiPhoneXsMaxAndXr = idiom == .phone && ScreenSize.maxLength == 896.0 | |
static let isiPad = idiom == .phone && ScreenSize.maxLength == 1024.0 | |
static func isiPhoneXAspectRation() -> Bool { | |
return isiPhoneX || isiPhoneXsMaxAndXr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We still need to support the old iPhoneSE so this utility Gist is helpful to adapt some of our UI to this old model.
Check this link for more pixels!
https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions