2013-10-09 160 views
2

您好我正在遷移我的應用程序從ios 6.1到7,該應用程序包含一個tabbar控制器,在ios6上工作完全正常,但是當我在5個標籤欄項目中運行ios 7,4時不顯示選擇的圖像,它是非常奇怪的,因爲一個正確顯示,而其他人不是,正在使用故事板,我無法使用「imageWithRenderingMode:」,因爲我仍然在xcode 4.6上做這個,所以我想糾正它在Xcode中只有4.6,並能夠在ios7運行,爲tabbarcontroller代碼給出,請原諒錯誤,如果任何..問題與ios7標籤欄控制器

- (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"]]; 
    } 
} 

enter image description here

enter image description here

enter image description here

回答

1

你是正確的軌道想要使用imageWithRenderingMode上。只要做這樣的事情來調整UIImage以與兩個ios版本兼容:

UIImage *tabImage = [UIImage imageNamed:@"tabBar.png"]; 

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) { 
    tabImage = [segmentImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
}