如何判断iPhoneX/iPhoneXR/iPhoneXs/iPhoneXsMax系列机型

通过定义宏判断如下:

/*当前机型是否iPhoneX或iPhoneXs*/
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

/*当前机型是否iPhoneXR*/
#define iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)

/*当前机型是否iPhoneXsMax*/
#define iPhoneXsMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)

/*当前机型是否iPhoneX系列*/
#define iPhoneXSeries (iPhoneX || iPhoneXR || iPhoneXsMax)

你可能感兴趣的:(如何判断iPhoneX/iPhoneXR/iPhoneXs/iPhoneXsMax系列机型)