2011-07-26 37 views
4

我需要將B項目相對於工具欄居中。我創建的界面生成以下內容:居中在UIToolBar上的按鈕

Item B in the center

它正常工作,直到我動態插入其他項目:

Item B not in the center

我如何能保持在B項目的靠近中心的位置?一個想法是使用固定空格欄按鈕項目,但我不能,因爲工具欄的長度也會改變(針對不同的方向)。

回答

1

您可以使用此每次標籤欄更改大小:

//lets be tabBar the big view and buttonB the.. well, button B 
[buttonB setCenter:CGPointMake(tabBar.frame.size.height/2, tabBar.frame.size.width/2); 
+0

一的UIBarButtonItem不是一個UIView,沒有'center'財產。你的代碼不會工作。 –

+0

哇..這是因爲UIToolbar和UINavigationBar是我認爲這也是。 – Rodrigo