怎么判断ios 版本

2025-05-19 05:42:21
推荐回答(1个)
回答(1):

在iOS开发中,经常要考虑系统的向下兼容,如果使用了低版本不存在的API ,则不能向下兼容,这时候如果想兼容低版本,就需要根据当前设备的版本进行不同的处理,在低版本中可能要牺牲一些新功能。
下面以UITabBarItem修改字体为例,说明一下如何向下兼容
From: http://www.giser.net/?p=955
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
// iOS 5 code
for(UITabBarItem *tabBarItem in self.tabBar.items)
{
[tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:14.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];
}
}
else {
// iOS 4.x code
;
}

#define IOS_VERSION_5_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)? (YES):(NO))
使用:

if (IOS_VERSION_5_OR_ABOVE) {
NSLog(@"IOS_VERSION_5_OR_ABOVE");
} else {
NSLog(@"NOT IOS_VERSION_5_OR_ABOVE");
}