iOS中判斷設(shè)備系統(tǒng)版本

字號(hào):


    在iOS開發(fā)中,經(jīng)常要考慮系統(tǒng)的向下兼容,如果使用了低版本不存在的API ,則不能向下兼容,這時(shí)候如果想兼容低版本,就需要根據(jù)當(dāng)前設(shè)備的版本進(jìn)行不同的處理,在低版本中可能要犧牲一些新功能。
    下面以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
    }