2012-05-15 151 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