2011-10-14 77 views
8

我利用IOS 5的UI自定義功能來創建自定義tabBar。我知道如何把一個自定義的背景和選擇項,像這樣:IOS 5 TabBar定製

-(void)customizeAppearance { 
    UIImage *tabBg = [UIImage imageNamed:@"myTabBar.png"]; 
    [[UITabBar appearance] setBackgroundImage:navBg]; 

    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"mySelector.png"]]; 
} 

我還想設置「選擇」和「未選中」圖片使用TabBar圖標。從文檔中,我看到您使用方法來完成此操作。我有4個選項卡,併爲他們創建了必要的8個圖標。問題是如何將每個選定/未選定的圖像集分配給每個選項卡?

+0

這太好了。我沒有注意到你可以自定義標籤欄。投票! :)你知道我是否可以使它的一部分透明,所以它不一定有矩形形狀? – Farini

回答

20

你可以在tabBar屬性中調用每個UITabBarItem的方法。例如:

UIImage *selectedImage = [UIImage imageNamed:@"selected.png"]; 
UIImage *unselectedImage = [UIImage imageNamed:@"unselected.png"]; 

UITabBar *tabBar = tabBarViewController.tabBar; 
UITabBarItem *item1 = [tabBar.items objectAtIndex:0]; 
[item1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage]; 

與其他三項相同。我希望這有幫助!

+0

感謝您回答這樣一個基本問題!我很感激,是的,這是我正在尋找的... – awDemo