2012-01-16 88 views

回答

0

您可以在左邊的最後一個項目和右邊的項目之間添加一個靈活的空間。

NSMutableArray *itemArray [[NSMutableArray alloc] init]; 

// Add items to the left 
... 

// Add flexible item to push everything else to the right 
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] inithWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
     target:nil 
     action:nil]; 
[itemArray addObject:flexItem]; 
[flexItem release]; 

// Add items to the right 
... 

self.toolbarItems = itemArray; 
[itemArray release]; 
+0

編輯UITabBarController的UITabBar似乎是不可能的。該物業爲只讀 – gsempe 2012-01-16 17:51:17

+1

哦對不起。我想工具欄不是Tabbar。我已經完成了你正在談論的通過向TabBar添加空標籤。您可以使用UITabbarContollerDelegate方法tabBarController:shouldSelectViewController:併爲空標籤返回NO。 – jimmyg 2012-01-18 05:56:23

+0

它似乎是UIViewContainers時代之前唯一可行的解​​決方案 – gsempe 2012-01-28 15:38:42

1

我會實例化一個UITabBarItem,其中標題和圖像的值爲零,值超出範圍的標記。

UITabBarItem *flexItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:999]; 

然後將這些添加到您的items數組以創建您希望的效果。

aTabBar.items = @[item1, item2, flexItem, flexItem, item3]; 

在使用TabBar:didSelectItem:回調添加交換機的情況下處理您的項目,讓通過默認情況下,flexItem的秋天。