刚发布的三款iPhone包括OLED屏幕的iPhone XS和iPhone XS Max,iPhone XR配备了6.1英寸LCD液晶屏。三款均采用了”刘海屏+Face ID设计”。

机型 尺寸 分辨率 像素点 像素比
iPhone XS Max 6.5英寸 1242 x 2688 414 x 896 @3x
iPhone XR 6.1英寸 828 x 1792 414 x 896 @2x
iPhone XS 5.8英寸 1125 x 2436 375 x 812 @3x
iPhone X 5.8英寸 1125 x 2436 375 x 812 @3x
8plus 5.5英寸 1242 x 2208 375 x 667 @3x
8 4.7英寸 750 x 133 375 x 812 @2x
SE 4.0英寸 640 x 1136 320 x 568 @2x

在项目中可以使用一下宏做适配。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#define JJ_ScreenWidth  [UIScreen mainScreen].bounds.size.width
#define JJ_ScreenHeight [UIScreen mainScreen].bounds.size.height

#define JJ_iPhoneX (JJ_ScreenWidth == 375.f && JJ_ScreenHeight == 812.f ? YES : NO)
#define JJ_iPhoneXS (JJ_ScreenWidth == 375.f && JJ_ScreenHeight == 812.f ? YES : NO)
#define JJ_iPhoneXR (JJ_ScreenWidth == 414.f && JJ_ScreenHeight == 896.f ? YES : NO)
#define JJ_iPhoneXSMax (JJ_ScreenWidth == 414.f && JJ_ScreenHeight == 896.f ? YES : NO)

// X系列
#define JJ_iPhoneXSeries ((JJ_iPhoneX && JJ_iPhoneXS && JJ_iPhoneXR && JJ_iPhoneXSMax) ? YES : NO)

#define JJ_StatusBarHeight (JJ_iPhoneXSeries ? 44.f : 20.f)
#define JJ_NavigationBarHeight 44.f
#define JJ_TabbarHeight (JJ_iPhoneXSeries ? (49.f+34.f) : 49.f)
#define JJ_TabbarSafeBottomMargin (JJ_iPhoneXSeries ? 34.f : 0.f)
#define JJ_StatusBarAndNavigationBarHeight (JJ_iPhoneXSeries ? 88.f : 64.f)
#define JJ_ViewSafeAreInsets(view) ({UIEdgeInsetsinsets; if(@available(iOS 11.0, *)) {insets = view.safeAreaInsets;} else{insets = UIEdgeInsetsZero;} insets;})