iOS

iPhoneX简单适配

2019-06-26  本文已影响0人  Joymerry

在pch文件中定义

// 导航栏底部
#define kGetNavAndStatusHeight  self.navigationController.navigationBar.frame.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height
// 状态栏高度
#define kGetStatusHeight  [[UIApplication sharedApplication] statusBarFrame].size.height
// 导航栏高度
#define kGetNavHeight  self.navigationController.navigationBar.frame.size.height
// 是否是iPhoneX以上刘海屏
#define is_iPhoneX (UIApplication.sharedApplication.statusBarFrame.size.height >= 44?YES:NO)
// Tabbar安全区域底部间隙
#define TabbarSafeBottomMargin  (is_iPhoneX ? 34.f : 0.f)
//状态栏 导航栏 tabbar  高度常量  适配iphoneX
#define StatusBarH (is_iPhoneX ? 44 : 20)
#define TabbarH (is_iPhoneX ? 83 : 49)
#define NavgationH 44
#define KNavHeight (NavgationH + StatusBarH)

解决iPhoneX屏幕tabbar适配后,底部安全区的颜色跟tabbar背景色一致

iPhoneX适配
// 设置一个自定义 View,大小等于 tabBar 的大小
    //UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, TabbarH + TabbarSafeBottomMargin)];
    // 给自定义 View 设置颜色
    bgView.backgroundColor = HRGB(0x343434);
    // 将自定义 View 添加到 tabBar 上
    [self.tabBar insertSubview:bgView atIndex:0];

其中TabbarH为导航栏的高度,TabbarSafeBottomMargin为底部安全距离

上一篇下一篇

猜你喜欢

热点阅读