现在的位置: 首页 > 综合 > 正文

自定义Navigationbaritem

2013年10月12日 ⁄ 综合 ⁄ 共 1796字 ⁄ 字号 评论关闭

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];
     

   

    



抱歉!评论已关闭.