2012-08-27 32 views
1

自iOS 5 Apple提供了一個API來自定義UITabBar對象中的UITabBarItems。我特別指的下列選擇:自定義UITabBar中的更多UIBarButtonItem

setFinishedSelectedImage:withFinishedUnselectedImage:

這一切的偉大工程進行定期按鈕,但我似乎無法自定義「更多」按鈕,以配合其他的風格。這是我在做什麼:

tabBarController.viewControllers = tabBarControllerArray; 
    tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor]; 
    UITabBarItem *more = tabBarController.moreNavigationController.tabBarItem; 
    if ([more respondsToSelector:@selector(setFinishedSelectedImage:withFinishedUnselectedImage:)]){ 
     [more setFinishedSelectedImage:[UIImage imageNamed:@"BarIcon-More.png"] 
      withFinishedUnselectedImage:[UIImage imageNamed:@"BarIcon-More.png"] 
     ]; 
    } else { 
     more.image = [UIImage imageNamed:@"BarIcon-More.png"]; 
    } 

結果如下,它不接受我的自定義更多圖片。

Inactive more button Ugly active more button

我見過很多黑客更換更按鈕,但也一定是這樣做的權利的更好的辦法?

回答

8

解決方案很愚蠢。

我認爲UITabBarItemsmoreNavigationController是隻讀的,它不是。因此,只需執行以下步驟:

tabBarController.moreNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"More" image:[UIImage imageNamed:@"BarIcon-More.png"] tag:0]; 

而且上面的定製代碼也適用。

+3

這似乎並不適用於iOS 6.在更多的控制器上設置'tabBarItem'屬性什麼也不做。我可以在調試器前後檢查賦值行,它不會改變。其他解決方案? –