iOS14/15/16/17/18 适配新iPhone 12/13/14/15/16五种系列机型

GitHub: https://github.com/GardenerYun
Email: gardeneryun@foxmail.com
简书博客地址: http://www.jianshu.com/users/8489e70e237d/latest_articles
如有问题或建议请联系我,我会马上解决问题~ (ง •̀_•́)ง

2024-09-25更新;

iPhone 16机型系列更新

2023-10-27更新;

iPhone 14 、 iPhone 15 机型见下表

2021-10-26更新;

iPhone 13四种机型与iPhone 12屏幕大小、分辨率、像素密度完全一致。见下表

1、适配新iPhone 12 四种机型

新增四种机型。整理的表格如下:

机型 物理分辨率 (pixel) 逻辑分辨率 (point) 像素密度 (PPI) 缩放因子 (切图规格) 状态栏高度
iPhone 5s/se1 640 × 1136 320 × 568 326 @2x 20
iPhone 6/6s/7/8/se2/se3 750 × 1334 375 × 667 326 @2x 20
iPhone 6/6s/7/8 Plus 1242 × 2208 (1080 × 1920) 414 × 736 401 @3x(2.62x) 20
iPhone X/XS/11 Pro 1125 × 2436 375 × 812 458 @3x 44
iPhone XR/11 828 × 1792 414 × 896 326 @2x 48
iPhone XS Max/11Pro Max 1242 × 2688 414 × 896 458 @3x 44
iPhone 12/13/14/12 Pro/13 Pro 1170 × 2532 390 × 844 460 @3x 47
iPhone 12/13 mini 1125 × 2436 (1080 × 2340) 375 × 812 476 @3x(2.88x) 44
iPhone 12/13 Pro Max/14 Plus 1284 × 2778 428 × 926 458 @3x 47
iPhone 14 Pro/15/15 Pro/16 1179 × 2556 393 × 852 460 @3x 54
iPhone 14 Pro Max/15 Plus/15 Pro Max/16 Plus 1290 × 2796 430 × 932 460 @3x 54
iPhone 16 Pro 1206 x 2622 402 x 874 460 @3x 54
iPhone 16 Pro Max 1320 x 2868 440 x 956 460 @3x 54

注意:iPhone 12 mini 与 iPhone 6 Plus 机型一样,先由标准的3X,然后系统转成的2.88X / 2.62X.

iPhone 12 mini 逻辑分辨率375 × 812 ,物理分辨率为1125 × 2436,然后系统转成实际分辨率1080 × 2340

iPhone 8 Plus 逻辑分辨率414 × 736 ,物理分辨率为1242 × 2208,然后系统转成实际分辨率1080 × 1920

2、iOS14状态栏高度的改变(统一维护在上表)

在iOS14中无意发现状态栏高度有一定变化,整理如下表格:
注意:使用Xcode12.0.1、Xcode12.1、Xcode12.2 中运行各屏幕模拟器获取的数据。(无iPhone 12真机测试 仅供参考,欢迎讨论)

机型 导航栏高度 状态栏高度 标签栏高度
iPhone 12 44pt 47pt 49pt
iPhone 12 Pro 44pt 47pt 49pt
iPhone 12 mini 44pt 44pt 49pt
iPhone 12 Pro MAX 44pt 47pt 49pt
iPhone XR 44pt 48pt 49pt
iPhone 11 44pt 48pt 49pt
iPhone 11 Pro 44pt 44pt 49pt
iPhone 11Pro MAX 44pt 44pt 49pt
iPhone 8 44pt 20pt 49pt
iPhone 8 Plus 44pt 20pt 49pt
iPhone 5s 44pt 20pt 49pt

3、宏定义代码

使用系统风格,包括导航栏、状态栏、标签栏的宏定义不写死高度。
仅供参考,欢迎讨论



#define iOS12 ([[UIDevice currentDevice].systemVersion floatValue] >= 12.0)

#define iOS13 ([[UIDevice currentDevice].systemVersion floatValue] >= 13.0)

#define iOS14 ([[UIDevice currentDevice].systemVersion floatValue] >= 14.0)

#define iOS15 ([[UIDevice currentDevice].systemVersion floatValue] >= 15.0)


#define iPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define iPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define kMaxScreenLength (MAX(kScreenWidth, kScreenHeight))
#define kMinScreenLength (MIN(kScreenWidth, kScreenHeight))

/**
 *  屏幕是否是iPhone4
 *          iPhone4S
 */
#define iPhone4 (iPhone && kMaxScreenLength == 480)


/**
 *  屏幕是否是iPhone 5
 *          iPhone 5S
 *          iPhone SE 1
 */
#define iPhone5 (iPhone && kMaxScreenLength == 568)


/**
 *  屏幕是否是iPhone 6
 *          iPhone 6S
 *          iPhone 7
 *          iPhone 8
 *          iPhone SE 2
 *          iPhone SE 3
 */
#define iPhone6 (iPhone && kMaxScreenLength == 667)

/**
 *  屏幕是否是iPhone 6  Plus
 *          iPhone 6S Plus
 *          iPhone 7  Plus
 *          iPhone 8  Plus
 *
 */
#define iPhone6Plus (iPhone && kMaxScreenLength == 736)

/**
 *  屏幕是否是iPhone X
 *          iPhone XS
 *          iPhone 11 Pro
 *          iPhone 12 mini
 *          iPhone 13 mini
 */
#define iPhoneX (iPhone && kMaxScreenLength == 812)
 
/**
 *  屏幕是否是iPhone XR
 *          iPhone XS Max
 *          iPhone 11
 *          iPhone 11 Pro Max
 */
#define iPhoneXSMax (iPhone && kMaxScreenLength == 896)

/**
 *  屏幕是否是iPhone 12
 *  屏幕是否是iPhone 12 Pro
 *  屏幕是否是iPhone 13
 *  屏幕是否是iPhone 13 Pro
 *  屏幕是否是iPhone 14
 */
#define iPhone12 (iPhone && kMaxScreenLength == 844)

/**
 *  屏幕是否是iPhone 12 Pro Max
 *  屏幕是否是iPhone 13 Pro Max
 *  屏幕是否是iPhone 14 Plus
 */
#define iPhone12ProMax  (iPhone && kMaxScreenLength == 926)

/**
 *  屏幕是否是iPhone 14 Pro
 *  屏幕是否是iPhone 15
 *  屏幕是否是iPhone 15 Pro
 */
#define iPhone14 Pro  (iPhone && kMaxScreenLength == 852)

/**
 *  屏幕是否是iPhone 14 Pro Max
 *  屏幕是否是iPhone 15 Plus
 *  屏幕是否是iPhone 15 Pro Max
 */
#define iPhone14ProMax  (iPhone && kMaxScreenLength == 932)

/**
 *  屏幕是否是iPhoneX及更新系列
 */
#define iPhoneXAndNewer (kSafeAreaHeight>0 && (iPhone && kMaxScreenLength >= 812))

/**
 *  屏幕高度
 */
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
/**
 *  屏幕宽度
 */
#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)


/**
 *  状态栏
 */
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height

/**
 *  导航栏
 */
#define kNavigationBarHeight [[UINavigationController alloc] init].navigationBar.frame.size.height

/**
 *  标签栏
 */
#define kTabBarHeight [[UITabBarController alloc] init].tabBar.frame.size.height


#define WeakSelf __weak typeof(self) weakSelf = self;
#define StrongSelf __strong __typeof__(self) strongSelf = self;

/**
 *  竖屏底部安全区域
 */
#define kSafeAreaHeight \
({CGFloat bottom=0.0;\
if (@available(iOS 11.0, *)) {\
bottom = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;\
} else { \
bottom=0;\
}\
(bottom);\
})

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容