更多的尺寸资料见:Apple开发者网站
机型号 | 屏幕尺寸 | 屏幕密度 | 开发尺寸 | 设计分辨率 | 倍率 |
---|---|---|---|---|---|
iPhone 4/4S | 3.5英寸 | 326ppi | 320*480pt | 640*960px | @2 |
iPhone 5/5S/5c | 4英寸 | 326ppi | 320*568pt | 640*1136px | @2x |
iPhone 6/6S/7/8 | 4.7英寸 | 326ppi | 375*667pt | 750*1334px | @2x |
iPhone 6/6S plus/ 7/8 plus | 5.5英寸 | 401ppi | 414*736pt | 1242*2208px | @3x |
iPhone X | 5.8英寸 | 458ppi | 375*812pt | 1125*2436px | @3x |
iPhone XS | 5.8英寸 | 458ppi | 375*812pt | 1125*2436px | @3x |
iPhone XS Max | 6.5英寸 | 458ppi | 414*896pt | 1242*2688px | @3x |
iPhone XR | 6.1英寸 | 326ppi | 414*896pt | 828*1792px | @2x |
iPhone 11 | 6.1英寸 | 326.ppi | 414*896pt | 828*1792px | @2x |
iPhone 11 Pro | 5.8英寸 | 458.ppi | 375*812pt | 1125*2436px | @3x |
iPhone 11 Pro Max | 6.5英寸 | 458ppi | 414*896pt | 1242*2688px | @3x |
iPhone SE(第二代) | 4.7英寸 | 326ppi | 375*667pt | 1334x750px | @3x |
iPhone 12 | 6.1英寸 | 460ppi | 390*844pt | 1170*2532px | @3x |
iPhone 12 mini/13 mini | 5.4英寸 | 476ppi | 360*780pt | 1080*2340px | @3x |
iPhone 12 Pro | 6.1英寸 | 460ppi | 390*844pt | 1170*2532px | @3x |
iPhone 12 Pro Max | 6.7英寸 | 458ppi | 428*926pt | 1284*2778px | @3x |
iPhone 13/13 Pro | 6.1英寸 | 460ppi | 390*844pt | 1170*2532p | @3x |
iPhone 13 Pro Max | 6.7英寸 | 458ppi | 428*926pt | 1284*2778px | @3x |
>机型判断的宏定义
// 判断 iPad
#define YYR_UI_IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// 判断iPhone X
#define YYR_IS_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
//判断iPHoneXr | 11
#define YYR_IS_iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !YYR_UI_IS_IPAD : NO)
//判断iPHoneXs | 11Pro
#define YYR_IS_iPhoneXS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !YYR_UI_IS_IPAD : NO)
//判断iPhoneXs Max | 11ProMax
#define YYR_IS_iPhoneXS_MAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !YYR_UI_IS_IPAD : NO)
//判断iPhone12_Mini
#define YYR_IS_iPhone12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !YYR_UI_IS_IPAD : NO)
//判断iPhone12 | 12Pro
#define YYR_IS_iPhone12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !YYR_UI_IS_IPAD : NO)
//判断iPhone12 Pro Max
#define YYR_IS_iPhone12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !YYR_UI_IS_IPAD : NO)
//x系列
#define YYR_IS_iPhoneX_All (YYR_IS_iPhoneX || YYR_IS_iPhoneXR || YYR_IS_iPhoneXS || YYR_IS_iPhoneXS_MAX || YYR_IS_iPhone12_Mini || YYR_IS_iPhone12 || YYR_IS_iPhone12_ProMax)
>一些尺寸与颜色相关的宏定义
let JSHColor = JSHexColor(Hex: 0x4891A1, alpha: 1)
let JSCREENW = UIScreen.main.bounds.size.width
let JSCREENH = UIScreen.main.bounds.size.height
let IPHONE_6_SCREENW = 375.0
let RealWidth = JSCREENW < JSCREENH ? JSCREENW : JSCREENH
let kRPViewRatio = RealWidth / CGFloat(IPHONE_6_SCREENW)
func kRPRealValue(_ value: CGFloat) -> CGFloat {
return kRPViewRatio * value
}
let IS_IPHONE_4_OR_LESS = ( JSCREENH <= 568.0)
let IS_IPHONE_5 = ( JSCREENH == 568.0)
let IS_IPHONE_678_OR_LESS = ( JSCREENH < 667.0)
let IS_IPHONE_5_OR_LESS = ( JSCREENH <= 667.0)
let IS_IPHONE_6P = ( JSCREENH == 736.0)
let IS_IPHONE_8P_OR_LESS = ( JSCREENH <= 736.0)
let IS_IPHONE_X = ( JSCREENH == 812.0)
let IS_IPHONE_Xs = ( JSCREENH == 896.0)
let IS_IPHONE_X_SERIES = (JSCREENH >= 812.0)
let IS_IPHONE11 = UIScreen.instancesRespond(to: #selector(getter: RunLoop.currentMode)) ? CGSize(width: 828, height: 1792).equalTo(UIScreen.main.currentMode!.size) : false
let IS_IPHONE11Pro = UIScreen.instancesRespond(to: #selector(getter: RunLoop.currentMode)) ? CGSize(width: 1125, height: 2436).equalTo(UIScreen.main.currentMode!.size) : false
let IS_IPHONEEleventh = (IS_IPHONE11 || IS_IPHONE11Pro)
// Status bar height.
let kStatusBarHeightXSwift: CGFloat = (IS_IPHONE_X_SERIES ? 44 : 20)
// Status bar safe top margin
let kStatusBarSafeTopMarginSwift: CGFloat = (IS_IPHONE_X_SERIES ? 24 : 0)
// Navigation bar height.
let kNavigationBarHeightSwift:CGFloat = 44
// Tabbar height.
let kTabbarHeightSwift: CGFloat = (IS_IPHONE_X_SERIES ? (49+34) : 49)
// Tabbar safe bottom margin.
let kTabbarSafeBottomMarginSwift: CGFloat = (IS_IPHONE_X_SERIES ? 34 : 0)
// Status bar & navigation bar height.
let kStatusBarAndNavigationBarHeightSwift: CGFloat = (IS_IPHONE_X_SERIES ? 88 : 64)
var ApplicationDelegate:JuAppDelegate { return UIApplication.shared.delegate as! JuAppDelegate }
//判断是真机还是模拟器的方法
struct Platform {
static let isSimulator: Bool = {
var isSim = false
#if arch(i386) || arch(x86_64)
isSim = true
#endif
return isSim
}()
}
func SystemSound(){
//建立的SystemSoundID对象,标准长震动
//let soundID = SystemSoundID(kSystemSoundID_Vibrate)
//短振动,普通短震,3D Touch 中 Peek 震动反馈
let soundShort = SystemSoundID(1519)
//普通短震,3D Touch 中 Pop 震动反馈,home 键的振动
//let soundMiddle = SystemSoundID(1520)
// 连续三次短震
//let soundThere = SystemSoundID(1521)
//执行震动
AudioServicesPlaySystemSound(soundShort)
}
var maskContainer:UIView = {
let maskContainer = UIView.init(frame: CGRect.init(x: 0, y: 0, width: JSCREENW, height: JSCREENH))
maskContainer.backgroundColor = getFilterColor(blueFilterPercent: 30).withAlphaComponent(0.3)
let keyWindow = UIApplication.shared.keyWindow
keyWindow?.addSubview(maskContainer)
keyWindow?.sendSubviewToBack(maskContainer)
maskContainer.layer.zPosition = 0
return maskContainer
}()
func getFilterColor(blueFilterPercent: CGFloat) -> UIColor{
var realFilter = blueFilterPercent
if realFilter < 10 {
realFilter = 10
}else if realFilter > 80{
realFilter = 80
}
let a = (realFilter / 80 * 180)
let r = (200 - realFilter / 80 * 190)
let g = (180 - realFilter / 80 * 170)
let b = (60 - realFilter / 80 * 60)
return JSColor(r: r, g: g, b: b, a: a)
}
func JSCGRect(x:CGFloat,y:CGFloat,_ width:CGFloat, _ height:CGFloat) -> CGRect{
return CGRect(x: x, y:y, width: width, height: height)
}
func JSColor(r:CGFloat,g:CGFloat,b:CGFloat,a:CGFloat) -> UIColor {
return UIColor(red:r/255.0,green:g/255.0,blue:b/255.0,alpha:a)
}
func JSHexColor(Hex:NSInteger,alpha:CGFloat) -> UIColor {
return UIColor(red:((CGFloat)((Hex & 0xFF0000) >> 16))/255.0,green:((CGFloat)((Hex & 0xFF00) >> 8))/255.0,blue:((CGFloat)(Hex & 0xFF))/255.0,alpha:alpha)
}
func JSScolor()-> UIColor{
return UIColor(red: CGFloat(arc4random_uniform(255))/CGFloat(255.0), green:CGFloat( arc4random_uniform(255))/CGFloat(255.0), blue:CGFloat(arc4random_uniform(255))/CGFloat(255.0),alpha:CGFloat(arc4random_uniform(255))/CGFloat(255.0))
}
//暗黑模式适配:白
public func Interfacewhite() -> UIColor{
if #available(iOS 13.0, *) {
let dyColor = UIColor.init { (trainCollection) -> UIColor in
if trainCollection.userInterfaceStyle == .light {
return .white
}else{
return JSHexColor(Hex: 0xffffff, alpha: 1)
}
}
return dyColor
} else {
return .white
}
}
//暗黑模式适配:黑
public func Interfaceblack() -> UIColor{
if #available(iOS 13.0, *) {
let dyColor = UIColor.init { (trainCollection) -> UIColor in
if trainCollection.userInterfaceStyle == .light {
return .black
}else{
return JSHexColor(Hex: 0x000000, alpha: 1)
}
}
return dyColor
} else {
return .black
}
}