iOS 適配各機(jī)型界面

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

1、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

2、下面就開(kāi)始適配了,其實(shí)也是很簡(jiǎn)單,通過(guò)宏定義去適配

//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ū)距離

3、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、字體適配

#definefont(R) (R)*(kScreenWidth)/375.0//這里是iPhone 6屏幕字體#definesysFont(f) [UIFont fontWithName:@"STHeitiSC-Light" size:autoScaleW(f)]

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容