關(guān)于iOS機(jī)型適配,相信大家都有自己的方法,這也是考驗(yàn)?zāi)托牡囊粋€(gè)事情,畢竟界面美觀也影響著用戶體驗(yàn),前段時(shí)間接觸的項(xiàng)目和之前用過(guò)的方法做一下總結(jié)。
1、先說(shuō)一下Apple的尺寸吧
se/5s {320, 568}
6s {375, 667}
iphonX {375, 812}
2、apple設(shè)備狀態(tài)欄和tabbar高度
iPhone X 全屏狀態(tài)欄statuBar高度為44,tabBar高度為83,底部狀態(tài)增加了34.
iPhone X以下機(jī)型狀態(tài)欄statuBar高度為20,tabBar高度為49
3、下面就開(kāi)始適配了,其實(shí)也是很簡(jiǎn)單,通過(guò)宏定義去適配
通過(guò)動(dòng)態(tài)獲取設(shè)備狀態(tài)欄的高度加入計(jì)算
//iPhone X適配
#define KStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height //獲取狀態(tài)欄的高度
#define KNavBarHeight 44.0 //導(dǎo)航欄的高度
#define KTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height > 20?83:49) //根據(jù)狀態(tài)欄的高度判斷tabBar的高度
#define KtopHeitht (KStatusBarHeight + KNavBarHeight) //頂部狀態(tài)欄加導(dǎo)航欄高度
#define KTabSpace ([[UIApplication sharedApplication] statusBarFrame].size.height > 20?34:0) //底部距安全區(qū)距離
4、UI界面的frame適配
// 當(dāng)前設(shè)備大小
#define iPhoneWidth [UIScreen mainScreen].bounds.size.width
#define iPhoneHeight [UIScreen mainScreen].bounds.size.height
//自適應(yīng)大小;這里使用的基于iphone6 的參考適配,可以修改為se/5s {320, 568}/ 6s {375, 667}/ iphonX {375, 812}
#define kWidth(width) iPhoneWidth * width / 375.
#define kHeight(height) iPhoneHeight * height / 667.
#define kLevelSpace(space) iPhoneWidth * space / 375. //水平方向距離間距
#define kVertiSpace(space) iPhoneHeight * space / 667. //垂直方向距離間距
5、字體適配
#define font(R) (R)*(kScreenWidth)/375.0 //這里是iPhone 6屏幕字體
#define sysFont(f) [UIFont fontWithName:@"STHeitiSC-Light" size:autoScaleW(f)]
先更新這么多吧,有不對(duì)或更好的方法歡迎指教,以后再更新吧.
----一點(diǎn)點(diǎn)進(jìn)步