views:

181

answers:

3

I am new to iphone development.I have created a UIBarButtonItem on the navigation bar.I want to set the proper to custom. There is no property as custom for "style:" attribute.Please help me out.Thanks.

leftbutton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"LEFT.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftbutton)];
self.navigationItem.leftBarButtonItem = leftbutton;
[self.navigationItem]
[leftbutton release];
+2  A: 

You can create item with - (id)initWithCustomView:(UIView *)customView method with whatever custom view you want.

Vladimir
Thanks for the answer.
Warrior
+1  A: 

UIBarButtonItem has 4 initializers which cover all you will ever need:

  • -initWithBarButtonSystemItem:target:action: for standard (built-in items);
  • -initWithTitle:style:target:action: for buttons with title and no image;
  • -initWithImage:style:target:action: for buttons with image and no title;
  • -initWithCustomView: for any UIView subclass, Apple's or your own.

The style property makes sense only for standard buttons.

Costique
Thanks for the answer.
Warrior
+2  A: 

If you just want to display a .png file inside the usual button frame from Apple, then your code is ok. If your png file is not displaying, just check if it's valid.

If you want to make your own button, you can use -(id)initWithCustomView:(UIView *)customView

Check this post for an interesting sample code : Custom Bar Button Sample Code

Christophe Konig
The sample code you gave was more worthy for me.Thanks.
Warrior