为了适配6.0版本,需要做额外处理,同时由于7.0版本以后新增了一些API,如果没有注意到这些变化,
设置了图片并没有达到预期的效果。
下面是关键代码,适配了6.0:
UITabBarItem *item2 = [[UITabBarItem alloc] init]; item2.title = @"消息"; if (kIOSVersion >= 7) { item2.image = [kImageWithName(@"messageUnselect") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item2.selectedImage = [kImageWithName(@"messageSelected") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [item2 setTitleTextAttributes:@{NSForegroundColorAttributeName : kAssistOrangeColor} forState:UIControlStateSelected]; [item2 setTitleTextAttributes:@{NSForegroundColorAttributeName : kBColor} forState:UIControlStateNormal]; } else { [item2 setFinishedSelectedImage:kImageWithName(@"messageSelected") withFinishedUnselectedImage:kImageWithName(@"messageUnselect")]; [item2 setTitleTextAttributes:@{UITextAttributeTextColor : kAssistOrangeColor} forState:UIControlStateSelected]; [item2 setTitleTextAttributes:@{UITextAttributeTextColor : kBColor} forState:UIControlStateNormal]; }