2014-09-25 32 views
3

iOS8似乎有些變化,現在我的標籤欄圖標都沒有正確顯示。大多數時候,他們不顯示,直到標籤被激活:iOS8如何設置TabBarItem圖像

enter image description here

但有時他們根本就不出現了,給我的只是一個藍色的大盒子(像每當我解僱一個觀點,即覆蓋了整個窗口):

enter image description here

這就是我所做的預iOS8上:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 
UITabBar *tabBar = tabBarController.tabBar; 
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; 
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]]; 
tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 
tabBarItem1.title = @""; 

回答

-1

這種方法是德普雷cated在iOS的8:

Use initWithTitle:image:selectedImage: or the image and selectedImage properties along with UIImageRenderingModeAlwaysOriginal

+0

我一直無法找到任何表明它已被棄用的內容。還設置圖像和selectedImage屬性不起作用。 – 2014-09-27 00:49:10

0

你有沒有嘗試setSelectedImage:?您可以使用以下任意一種方法來顯示圖片:[url = http://www.google.com/support/downloads/details.asp?url=/library/en-us/library/default.aspx]

它適用於我的部分。如前所述

1

,如果你看一看:

https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITabBarItem_Class/index.html#//apple_ref/occ/instm/UITabBarItem/setFinishedSelectedImage:withFinishedUnselectedImage

你會發現,這種方法已被棄用,嘗試改變:

[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]]; 

到:

[tabBarItem1 setImage:[[UIImage imageNamed:@"paintbrush-white.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"paintbrush-black.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 

您可能也有圖像大小的問題,取決於大小當在iPhone 5屏幕和iPhone 6屏幕上進行測試時,顯示的圖像爲@ 2x圖像