问题
hi i am migrating my app from ios 6.1 to 7, the app contains a tabbar controller, works perfectly fine on ios6, but when i run this on ios 7, 4 among the 5 tabbar items dont show the selected image, its being pretty weird as one is showing correctly while the others are not, am using storyboard, am not able to use "imageWithRenderingMode:" as i am still doing this on xcode 4.6, so i would like to rectify it in xcode 4.6 only and be able to run it on ios7, the code for the tabbarcontroller is given, please forgive mistake if any..
- (void)customizeTabbarBackgroundImages:(UITabBarController *)tabbarController
{
//background of tabbar
[tabbarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbarBackground.png"]];
//background for selected item
[[tabbarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar-selection-background.png"]];
//keep the item at index 2 as selected item
tabbarController.selectedIndex = 2;
}
- (void)customizeTabbarItemImages:(UITabBarController *)tabbarController
{
{
//Index - Favourites
[[tabbarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-favourites-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-favourites-icon.png"]];
//Index - Search
[[tabbarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-search-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-search-icon.png"]];
//Index - Icon
[[tabbarController.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-random-button"]withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-random-button"]];
//Index - Profile
[[tabbarController.tabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-profile-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-profile-icon.png"]];
//Index - Settings
[[tabbarController.tabBar.items objectAtIndex:4] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-settings-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-settings-icon.png"]];
}
}
回答1:
You're on the right track with wanting to use imageWithRenderingMode. Just do something like this to adjust the UIImage to be compatible with both ios versions:
UIImage *tabImage = [UIImage imageNamed:@"tabBar.png"];
if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
tabImage = [segmentImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
来源:https://stackoverflow.com/questions/19270143/issue-with-ios7-tabbar-controller