iOS-(OC+Swift)机型判断

OC版本:

/// 判断是不是ipad

#define YIsPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

/// 判断iPhone4系列

#define YiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPhone5系列

#define YiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPhone6系列

#define YiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750,1334), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iphone6+系列

#define YiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2208), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPHoneXr

#define YiPhone_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828,1792), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPhoneX

#define YiPhone_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125,2436), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPhoneXs Max

#define YiPhone_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2688), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPhone12Mini

#define YiPhone_12Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080,2340), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPhone12

#define YiPhone_12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170,2532), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 判断iPhone12 Pro Max

#define YiPhone_12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284,2778), [[UIScreen mainScreen] currentMode].size) && !YIsPad : NO)

/// 是否是X及以上手机

#define YiPhoneE_X_orMore (YiPhone_Xr==YES || YiPhone_X== YES || YiPhone_Xs_Max== YES || YiPhone_12Mini== YES || YiPhone_12==YES || YiPhone_12_ProMax== YES)


Swift版本:

///苹果尺寸

public enum IPhoneSize: Int {

    case iphone4

    case iphone5s

    case iphone6

    case iphone6P

    /// 所有带刘海屏的手机统称X

    case iphoneX

}

///机型屏幕尺寸

public func IPhoneSizeAction () -> IPhoneSize {

    /*

     手机设备型号    屏幕尺寸    分辨率点数 (pt)    屏幕显示模式    分辨率像素(px)    屏幕比例

     iPhone 3GS    3.5吋    320 x 480    @1x    320 x 480    - 

     iPhone 4/4S    3.5吋    320 x 480    @2x    640 x 960    - 

     iPhone 5/5S/5C/SE    4.0吋    320x568    @2x    640x1136    16:9

     iPhone 6/6s/7/8/SE 2    4.7吋    375x667    @2x    750x1334    16:9

     iPhone 6p/7p/8p    5.5吋    414x736    @3x    1242x2208    16:9

     iPhone XR/11    6.1吋    414x896    @2x    828x1792    19.5:9

     iPhone X/XS/11 Pro    5.8吋    375x812    @3x    1125x2436    19.5:9

     iPhone XS Max/11 Pro Max    6.5吋    414x896    @3x    1242x2688    19.5:9

     iPhone 12 mini    5.4吋    360x780    @3x    1080x2340    19.5:9

     iPhone 12/12 Pro    6.1吋    390x844    @3x    1170x2532    19.5:9

     iPhone 12 Pro Max    6.7吋    428x926    @3x    1284x2778    19.5:9

     iPhone 13 mini    5.4吋    360x780    @3x    1080x2340    19.5:9

     iPhone 13/13 Pro    6.1吋    390x844    @3x    1170x2532    19.5:9

     iPhone 13 Pro Max    6.7吋    428x926    @3x    1284x2778    19.5:9

     */


    if UIScreen.height == 780// 12 mini/13 mini

        ||UIScreen.height==812// X/XS/11 Pro

        ||UIScreen.height == 896// XR/11/XS Max/11 Pro Max

        ||UIScreen.height == 844// 12/12 Pro/13/13 Pro

        ||UIScreen.height == 926// 12 Pro Max/13 Pro Max

    {

        return IPhoneSize.iphoneX

    }else if UIScreen.height == 736 {// 6 Plus/6S Plus/7 Plus/8 Plus

        return IPhoneSize.iphone6P

    }else if UIScreen.height == 667 {// 6/6S/7/8/SE(二代)

        return IPhoneSize.iphone6

    }else if UIScreen.height == 568{// 5/5S/5C/SE

        return IPhoneSize.iphone5s

    }else{

        return IPhoneSize.iphone4

    }

}

你可能感兴趣的:(iOS-(OC+Swift)机型判断)