Skip to content

Instantly share code, notes, and snippets.

@multitudes
Created May 14, 2020 11:20
Show Gist options
  • Save multitudes/0e24228fdb20032d2517c1cf37dee33a to your computer and use it in GitHub Desktop.
Save multitudes/0e24228fdb20032d2517c1cf37dee33a to your computer and use it in GitHub Desktop.
DeviceType and ScreenSize for iPhone's
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
}
@multitudes
Copy link
Author

multitudes commented May 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment