1

Possible Duplicate:
How to resize UIBarButtonItem in code

I tried setting the size of the UIBarButtonItem using IB, but in vain

enter image description here

I want to reduce the width & increase the height. How do I do it? Any pointers please? Setting the width attribute (shown in the figure above) doesn't seem to alter anything. I tried setting it programmatically too like this:

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

this too doesn't alter anything.

This is the bar-button (the one in red) that am trying to fix:

enter image description here

Community
  • 1
  • 1
Jean
  • 2,611
  • 8
  • 35
  • 60

1 Answers1

-5

You need to resize the frame of the UIBarButtonIte

Sth like :

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

You can see it in this tutorial :

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

Damien Locque
  • 1,810
  • 2
  • 20
  • 42
  • 3
    Thanks for your response. But, There isn't any 'frame' attribute for the button – Jean May 16 '12 at 01:47
  • 3
    That's why i link the tutorial, check it part 4, start to create a sample button (change his frame, picture ...) and then init your UIBarButton with customview UIBarButtonItem *CustomBarButton = [[UIBarButtonItem alloc]initWithCustomView:MyVCustomWithCustomFrame]; – Damien Locque May 16 '12 at 07:58
  • 1
    this didnt work at all. terrible answer. the tutorial specifically says in section 4 "NOT FOR USE IN THE NAVIGATION BAR". – Katushai May 31 '14 at 05:49
  • UIBarButtonItem doesn't have any frame property – Ashik Oct 31 '16 at 07:39