0

Possible Duplicate:
Custom UINavigationBar’s backButton?

I want to add custom button as left UIBarButtonItem. I have used following code

UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menu.png"] style:UIBarButtonItemStylePlain target:self action:@selector(showMenu:)];
self.navigationBar.leftBarButtonItem = menuButton;  

This does not show button but i can click & selector is called properly.

I also tried following way:

UIButton *menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
[menuButton setImage:[UIImage imageNamed:@"menu.png"] forState:UIControlStateNormal];
[menuButton addTarget:self action:@selector(showMenu:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barMenuItem = [[UIBarButtonItem alloc] initWithCustomView:menuButton];
self.navigationItem.leftBarButtonItem = barMenuItem;  

This shows the button & also clickable but button width is equal to default back button width. My Button image width is less than default back button image. So it centers the image in button with elongated width.

Any help is appreciated.

Sayali

Community
  • 1
  • 1
Sayali
  • 593
  • 3
  • 9
  • 22
  • Did you tried UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menu.png"] style:UIBarButtonItemStylePlain target:self action:@selector(showMenu:)]; ? self.navigationItem.leftBarButtonItem = menuButton; – Dave Nov 29 '12 at 13:42

1 Answers1

0

the simple way is just you create a new view and add button and then this view add on left button this is work properly and fine on my side if any question comment me

Waseem Shah
  • 2,219
  • 23
  • 23