首页 > 代码库 > 为UIButtonBarItem创建分类
为UIButtonBarItem创建分类
#import "UIBarButtonItem+Extension.h"
@implementation UIBarButtonItem (Extension)
+(UIBarButtonItem *)itemWithImageName:(NSString *)ImageName highImageName:(NSString *)highImageName target:(id)target action:(SEL)action{
UIButton *btn=[[UIButton alloc] init];
[btn setBackgroundImage:[UIImage imageNamed:ImageName] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:highImageName] forState:UIControlStateHighlighted];
btn.frame=CGRectMake(0, 0, btn.currentBackgroundImage.size.width, btn.currentBackgroundImage.size.height);
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc]initWithCustomView:btn];
}
@end
为UIButtonBarItem创建分类