2012-05-15 150 views
1

可能重複:
How to resize UIBarButtonItem in code設置大小

我嘗試設置的UIBarButtonItem使用IB的大小,但不成功

enter image description here

我想減少寬度&增加 高度。我該怎麼做?任何指針?設置width屬性(如上圖所示)似乎沒有改變任何東西。我嘗試以編程方式將其設置爲:

UIBarButtonItem *historyButton = [[UIBarButtonItem alloc] 
            initWithTitle:@"History" style:UIBarButtonItemStyleBordered target:self action:@selector(history:)]; 
historyButton.width = 3.0; 

這也不會改變任何內容。

這是酒吧按鈕(一個以紅色),其正在試圖修復:

enter image description here

+0

應該不應該改變UINavigationBar上UIBarItem的高度。思考的食物 –

回答

-5

您需要調整UIBarButtonIte

的......像框架:

historyButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height); 

你可以在本教程中看到它:

http://iphone-dev-kitchan.blogspot.fr/2010/05/customizing-uibarbutton-on.html

+3

感謝您的回覆。但是,沒有任何「框架」屬性的按鈕 – Jean

+3

這就是爲什麼我鏈接教程,檢查它的第4部分,開始創建一個示例按鈕(更改他的框架,圖片...),然後 初始您的UIBarButton with customview UIBarButtonItem * CustomBarButton = [[UIBarButtonItem alloc] initWithCustomView:MyVCustomWithCustomFrame]; –

+0

這沒有奏效。可怕的答案。本教程在第4節「不適用於導航欄」中特別說明。 – Katushai