//
// UIBarButtonItem+Extension.h
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (Extension)
/**
* 快速创建一个UIBarButtonItem
*
* @param image 普通状态下的图片
* @param highImage 高亮状态下的图片
* @param target 目标
* @param action 方法
*/
+ (instancetype) itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action;
@end
//
// UIBarButtonItem+Extension.m
#import "UIBarButtonItem+Extension.h"
@implementation UIBarButtonItem (Extension)
+ (instancetype) itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
button.size = button.currentBackgroundImage.size;
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[self alloc] initWithCustomView:button];
}
@end