iOS系統(tǒng)類庫里面有一個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
這些宏定義可以判斷當前系統(tǒng)版本是否是大于等于某個版本,例如:
#ifdef __IPHONE_7_0
- (UIRectEdge)edgesForExtendedLayout {
return UIRectEdgeNone;
}
#endif
判斷系統(tǒng)版本是否在iOS 7.0以上,如果是則執(zhí)行中間的代碼.
為什么這樣就可以判斷系統(tǒng)版本呢?
因為如果iOS的系統(tǒng)是7.0族扰,那么肯定有這樣一個宏定義“#define __IPHONE_7_0 70000”;如果系統(tǒng)版本低于7.0肯定沒有這個宏定義