// // UIBarButtonItem+Extension.m // 黑马微博2期 // // Created by apple on 14-10-7. // Copyright (c) 2014年 heima. All rights reserved. // #import "UIBarButtonItem+Extension.h" @implementation UIBarButtonItem (Extension) + (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; // 设置图片 [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; [btn setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted]; // 设置尺寸 btn.size = CGSizeMake(btn.currentImage.size.width+20, btn.currentImage.size.height+16); btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; return [[UIBarButtonItem alloc] initWithCustomView:btn]; } @end