-
-
Save rbrovko/8d007e3fa970c2fc5ff22900c9e55cc5 to your computer and use it in GitHub Desktop.
Display mode
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
import UIKit | |
public enum DisplayType { | |
case unknown | |
case iphone4 | |
case iphone5 | |
case iphone6 | |
case iphone6plus | |
static let iphone7 = iphone6 | |
static let iphone7plus = iphone6plus | |
case iphoneX | |
} | |
public final class Display { | |
class var width:CGFloat { return UIScreen.main.bounds.size.width } | |
class var height:CGFloat { return UIScreen.main.bounds.size.height } | |
class var maxLength:CGFloat { return max(width, height) } | |
class var minLength:CGFloat { return min(width, height) } | |
class var zoomed:Bool { return UIScreen.main.nativeScale >= UIScreen.main.scale } | |
class var retina:Bool { return UIScreen.main.scale >= 2.0 } | |
class var phone:Bool { return UIDevice.current.userInterfaceIdiom == .phone } | |
class var pad:Bool { return UIDevice.current.userInterfaceIdiom == .pad } | |
class var carplay:Bool { return UIDevice.current.userInterfaceIdiom == .carPlay } | |
class var tv:Bool { return UIDevice.current.userInterfaceIdiom == .tv } | |
class var typeIsLike:DisplayType { | |
if phone && maxLength < 568 { | |
return .iphone4 | |
} | |
else if phone && maxLength == 568 { | |
return .iphone5 | |
} | |
else if phone && maxLength == 667 { | |
return .iphone6 | |
} | |
else if phone && maxLength == 736 { | |
return .iphone6plus | |
} | |
else if phone && maxLength == 812 { | |
return .iphoneX | |
} | |
return .unknown | |
} | |
} |
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
print("width: \(Display.width)") | |
print("height: \(Display.height)") | |
print("maxLength: \(Display.maxLength)") | |
print("minLength: \(Display.minLength)") | |
print("zoomed: \(Display.zoomed)") | |
print("retina: \(Display.retina)") | |
print("phone: \(Display.phone)") | |
print("pad: \(Display.pad)") | |
print("carplay: \(Display.carplay)") | |
print("tv: \(Display.tv)") | |
print("Type is like: \(Display.typeIsLike)") |
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
// iphone 6s without launch screen | |
width: 320.0 | |
height: 480.0 | |
maxLength: 480.0 | |
minLength: 320.0 | |
zoomed: false | |
retina: true | |
phone: true | |
pad: false | |
carplay: false | |
tv: false | |
Type is like: iphone4 | |
// iphone SE portrait | |
width: 320.0 | |
height: 568.0 | |
maxLength: 568.0 | |
minLength: 320.0 | |
zoomed: true | |
retina: true | |
phone: true | |
pad: false | |
carplay: false | |
tv: false | |
Type is like: iphone5 | |
// iphone 7 plus portrait | |
width: 414.0 | |
height: 736.0 | |
maxLength: 736.0 | |
minLength: 414.0 | |
zoomed: true | |
retina: true | |
phone: true | |
pad: false | |
carplay: false | |
tv: false | |
Type is like: iphone6plus | |
// iphone 7 plus landscape | |
width: 736.0 | |
height: 414.0 | |
maxLength: 736.0 | |
minLength: 414.0 | |
zoomed: true | |
retina: true | |
phone: true | |
pad: false | |
carplay: false | |
tv: false | |
Type is like: iphone6plus | |
// iphone x | |
width: 375.0 | |
height: 812.0 | |
maxLength: 812.0 | |
minLength: 375.0 | |
zoomed: true | |
retina: true | |
phone: true | |
pad: false | |
carplay: false | |
tv: false | |
Type is like: iphoneX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment