自定义Navigationbaritem

From : http://stackoverflow.com/questions/3300527/add-image-to-uibarbuttonitem-using-initwithimageuiimage-image 

&& 

  MOMO老师的iOS   http://blog.csdn.net/xys289187120/article/details/6864293

add image to UIBarButtonItem using initWithImage:(UIImage *)image

Q:

I would like to know how to set an image to a UIBarButtonItem which will then be added to a UIToolbar, by using InitWithImage when creating a UIBarButtonItem.

I am doing the following, but it creates a blank whitespace where the image should be on the UIToolbar

UIImage *image = [UIImage imageNamed:@"6.png"];

UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithImage:image style:
:UIBarButtonItemStylePlain target:self action:@selector(pp:)];


A:

1. 完全的定制自己的navgBaritem。(我再3出加入了action的调用功能)

Here's an example that creates a toolbar button from the Facebook logo. Create a pointer to an image (file already added to xCode), create a custom button, change the size of the button to match the image, set image of button, create toolbar button from button view.

UIImage *faceImage = [UIImage imageNamed:@"facebook.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
face.bounds = CGRectMake( 0, 0, faceImage.size.width, faceImage.size.height );
[face setImage:faceImage forState:UIControlStateNormal];
UIBarButtonItem *faceBtn = [[UIBarButtonItem alloc] initWithCustomView:face];
	2  NavBaritem的 图片确实改过来了
IBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image.png"] style:UIBarButtonItemStylePlain target:self action:@selector(pp:)]
      3. 
    UIImage *faceImage = [UIImage imageNamed:@"nav_back.png"];
    UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];    
    face.bounds = CGRectMake( 0, 0, faceImage.size.width, faceImage.size.height );
    [face setImage:faceImage forState:UIControlStateNormal];
   
    [face addTarget:self action:@selector(clickLeftButton) forControlEvents:UIControlEventTouchDown];
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:face];
     

   

    



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值