美文网首页实用轮子
#define判断版本

#define判断版本

作者: 简简蜗牛 | 来源:发表于2016-04-02 19:46 被阅读197次

iOS系统类库里面有一个Availability.h头文件,有一些宏定义。

#define __IPHONE_2_0     20000

#define __IPHONE_2_1     20100

#define __IPHONE_2_2     20200

#define __IPHONE_3_0     30000

#define __IPHONE_3_1     30100

#define __IPHONE_3_2     30200

#define __IPHONE_4_0     40000

#define __IPHONE_4_1     40100

#define __IPHONE_4_2     40200

#define __IPHONE_4_3     40300

#define __IPHONE_5_0     50000

#define __IPHONE_5_1     50100

#define __IPHONE_6_0     60000

#define __IPHONE_6_1     60100

#define __IPHONE_7_0     70000

#define __IPHONE_7_1     70100

#define __IPHONE_8_0     80000

#define __IPHONE_8_1     80100

#define __IPHONE_8_2     80200

#define __IPHONE_8_3     80300

#define __IPHONE_8_4     80400

这些宏定义可以判断当前系统版本是否是大于等于某个版本,例如:

#ifdef __IPHONE_7_0

- (UIRectEdge)edgesForExtendedLayout {

   return UIRectEdgeNone;

}

#endif

判断系统版本是否在iOS 7.0以上,如果是则执行中间的代码.

为什么这样就可以判断系统版本呢?

因为如果iOS的系统是7.0,那么肯定有这样一个宏定义“#define __IPHONE_7_0     70000”;如果系统版本低于7.0肯定没有这个宏定义

相关文章

网友评论

    本文标题:#define判断版本

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