Skip to content

Instantly share code, notes, and snippets.

@imjhk03
Last active December 13, 2020 14:44
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 imjhk03/f242c2abe5d73a4d58786944184d33ce to your computer and use it in GitHub Desktop.
Save imjhk03/f242c2abe5d73a4d58786944184d33ce to your computer and use it in GitHub Desktop.
Get screen size or device types of iPhone
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 DeviceTypes {
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 == .pad && ScreenSize.maxLength >= 1024.0
static func isiPhoneXAspectRatio() -> Bool {
return isiPhoneX || isiPhoneXsMaxAndXr
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment