UIBarButtonItem的一个分类,用户快速创建一个UIBarButtonItem

来源:互联网 发布:怎么看淘宝运费险退款 编辑:程序博客网 时间:2024/06/03 19:44
////  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

0 0
原创粉丝点击