Last active
October 25, 2018 03:02
-
-
Save yoshiki-0428/519e84ae9010f9fb11503a0b907a69cb to your computer and use it in GitHub Desktop.
【iPhoneXR,Xs,XsMaxの判別対応】Nativeコード内での判別方法(解像度での判別) ref: https://qiita.com/yoshiki-0428/items/30151967574791a02a0c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ScreenHeight [UIScreen mainScreen].nativeBounds.size.height | |
#define ScreenWidth [UIScreen mainScreen].nativeBounds.size.width | |
#define ScreenScale [UIScreen mainScreen].scale | |
// iphoneX以上の端末を判別 | |
+ (BOOL)isIphoneXOver { | |
return (Device.isIphoneX || Device.isIphoneXs || Device.isIphoneXR || UIDevice.isIphoneXsMax); | |
} | |
+ (BOOL)isIphoneX { | |
return [self checkIPhoneSize:1125.0 height:2436.0 scale:3.0]; | |
} | |
+ (BOOL)isIphoneXs { | |
return [self checkIPhoneSize:1125.0 height:2436.0 scale:3.0]; | |
} | |
+ (BOOL)isIphoneXR { | |
return [self checkIPhoneSize:828.0 height:1792.0 scale:2.0]; | |
} | |
+ (BOOL)isIphoneXsMax { | |
return [self checkIPhoneSize:1242.0 height:2688.0 scale:3.0]; | |
} | |
+ (BOOL)checkIphoneSize:(CGFloat)width height:(CGFloat)height scale:(CGFloat)scale { | |
static BOOL result = NO; | |
if (@available(iOS 11.0, *)) { | |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
result = ((ScreenWidth == width && ScreenHeight == height) && ScreenScale == scale); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment