2011-12-27 90 views
8

如何將UIBarButtonItem的寬度更改爲29px?屬性寬度不起作用,我不想創建UIButton並使用initWithCustomView,因爲我想讓方形背景適應導航欄的顏色。 我正在使用initWithImage來初始化UIBarButtonItem更改UIBarButtonItem的寬度

這是我的按鈕,當前寬度爲37px。我想設置爲29px。

UIButton

+0

@MaxMacLeod提問者明確不想使用initWithCustomView ... – 2013-07-21 02:36:25

回答

16

你不能。如果你想定製的寬度,你將需要使用initWithCustomView

+2

但是他們爲什麼在UIBarButtonItem類中有屬性寬度? – gnclmorais 2011-12-28 10:02:33

+12

只有在UIToolbar中有按鈕時才能使用它 – RolandasR 2011-12-28 10:36:57

6

您可以將圖像從界面生成器拖放到欄按鈕項目並更改自定義視圖的寬度與此代碼做到這一點:

CGRect frame = self.navigationItem.leftBarButtonItem.customView.frame; 
frame.size.width = 141; 
self.navigationItem.leftBarButtonItem.customView.frame = frame;