开发者

How to set the button created in the navigation bar as custom in iphone?

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]
[leftbut开发者_如何转开发ton release];


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜