美文网首页
iOS常用判断的宏定义:系统版本号,屏幕宽高,设备型号, 自定

iOS常用判断的宏定义:系统版本号,屏幕宽高,设备型号, 自定

作者: 灰客 | 来源:发表于2017-09-22 15:30 被阅读0次

    //设备型号

    define IS_IPAD [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad

    define IS_IPHONE [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone

    define IS_IPHONE_4 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double )480) < DBL_EPSILON )

    define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double )568) < DBL_EPSILON )

    define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double )667) < DBL_EPSILON )

    define IS_IPHONE_6_PLUS (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double )960) < DBL_EPSILON )

    //系统版本

    define IS_IOS_VERSION floorf([[UIDevice currentDevice].systemVersion floatValue]

    define IS_IOS_7 floorf([[UIDevice currentDevice].systemVersion floatValue]) ==7.0 ? 1 : 0

    define IS_IOS_8 floorf([[UIDevice currentDevice].systemVersion floatValue]) ==8.0 ? 1 : 0

    define IS_IOS_9 floorf([[UIDevice currentDevice].systemVersion floatValue]) ==9.0 ? 1 : 0

    define IS_IOS_10 floorf([[UIDevice currentDevice].systemVersion floatValue]) ==10.0 ? 1 : 0

    define IS_IOS_11 floorf([[UIDevice currentDevice].systemVersion floatValue]) ==11.0 ? 1 : 0

    //物理屏幕尺寸

    define IH_DEVICE_HEIGHT [[UIScreen mainScreen] bounds].size.height

    define IH_DEVICE_WIDTH [[UIScreen mainScreen] bounds].size.width

    //自定义的NSLog

    ifdef DEBUG

    define XSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:FILE] lastPathComponent] UTF8String], LINE, [[NSString stringWithFormat:FORMAT, ##VA_ARGS] UTF8String]);

    define YYLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:FILE] lastPathComponent] UTF8String], LINE, [[NSString stringWithFormat:FORMAT, ##VA_ARGS] UTF8String]);

    else

    define XSLog(FORMAT, ...) nil;

    define YYLog(FORMAT, ...) nil;

    endif

    相关文章

      网友评论

          本文标题: iOS常用判断的宏定义:系统版本号,屏幕宽高,设备型号, 自定

          本文链接:https://www.haomeiwen.com/subject/uksfextx.html