如何將UIBarButtonItem
的寬度更改爲29px?屬性寬度不起作用,我不想創建UIButton
並使用initWithCustomView
,因爲我想讓方形背景適應導航欄的顏色。 我正在使用initWithImage
來初始化UIBarButtonItem
。更改UIBarButtonItem的寬度
這是我的按鈕,當前寬度爲37px。我想設置爲29px。
如何將UIBarButtonItem
的寬度更改爲29px?屬性寬度不起作用,我不想創建UIButton
並使用initWithCustomView
,因爲我想讓方形背景適應導航欄的顏色。 我正在使用initWithImage
來初始化UIBarButtonItem
。更改UIBarButtonItem的寬度
這是我的按鈕,當前寬度爲37px。我想設置爲29px。
你不能。如果你想定製的寬度,你將需要使用initWithCustomView
但是他們爲什麼在UIBarButtonItem類中有屬性寬度? – gnclmorais 2011-12-28 10:02:33
只有在UIToolbar中有按鈕時才能使用它 – RolandasR 2011-12-28 10:36:57
您可以將圖像從界面生成器拖放到欄按鈕項目並更改自定義視圖的寬度與此代碼做到這一點:
CGRect frame = self.navigationItem.leftBarButtonItem.customView.frame;
frame.size.width = 141;
self.navigationItem.leftBarButtonItem.customView.frame = frame;
@MaxMacLeod提問者明確不想使用initWithCustomView ... – 2013-07-21 02:36:25