iOS中判断设备系统版本

在iOS开发中,经常要考虑系统的向下兼容,如果使用了低版本不存在的API ,则不能向下兼容,这时候如果想兼容低版本,就需要根据当前设备的版本进行不同的处理,在低版本中可能要牺牲一些新功能。

下面以UITabBarItem修改字体为例,说明一下如何向下兼容

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

}

 

 

 转载:http://www.giser.net/?p=955

 

posted @ 2015-03-16 11:32  罕见  阅读(233)  评论(0编辑  收藏  举报