UIButtonCreate.h #import <UIKit/UIKit.h> @interface UIButtonCreate : UIButton /** * 创建UIButton * * @param frame frame * @param title title * @param titleColor titleColor * @param backgroundImage backgroundImage * @param highlightedImage highlightedImage * @param target target * @param selector selector */ - (void)createButtonWithbackgroundImage: (CGRect) frame title:(NSString *)title titleColor:(UIColor *)titleColor backgroundImage:(UIImage *)backgroundImage highlightedImage:(UIImage *)highlightedImage Target:(id)target Selector:(SEL)selector; /** * 创建UIButton * * @param frame frame * @param title title * @param titleColor titleColor * @param backgroundImage backgroundImage * @param highlightedImage highlightedImage * @param image image * @param target target * @param selector selector */ - (void)createButtonWithImageAndbackgroundImage: (CGRect) frame title:(NSString *)title titleColor:(UIColor *)titleColor backgroundImage:(UIImage *)backgroundImage highlightedImage:(UIImage *)highlightedImage image:(UIImage *)image Target:(id)target Selector:(SEL)selector; /** * 创建UIButton * * @param frame frame * @param title title * @param titleColor titleColor * @param backgroundColor backgroundColor * @param target target * @param selector selector */ - (void)createNormalButton: (CGRect) frame title:(NSString *)title titleColor:(UIColor *)titleColor backgroundColor:(UIColor *)backgroundColor Target:(id)target Selector:(SEL)selector; @end /****************************************************/ UIButtonCreate.m #import "UIButtonCreate.h" @implementation UIButtonCreate - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ - (void)createButtonWithbackgroundImage: (CGRect) frame title:(NSString *)title titleColor:(UIColor *)titleColor backgroundImage:(UIImage *)backgroundImage highlightedImage:(UIImage *)highlightedImage Target:(id)target Selector:(SEL)selector { [self setFrame:frame]; [self setTitle:title forState:UIControlStateNormal]; [self setTitleColor:titleColor forState:UIControlStateNormal]; [self setBackgroundImage:backgroundImage forState:UIControlStateNormal]; [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; [self setBackgroundColor:[UIColor clearColor]]; [self addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside]; } - (void)createButtonWithImageAndbackgroundImage: (CGRect) frame title:(NSString *)title titleColor:(UIColor *)titleColor backgroundImage:(UIImage *)backgroundImage highlightedImage:(UIImage *)highlightedImage image:(UIImage *)image Target:(id)target Selector:(SEL)selector { [self setFrame:frame]; [self setTitle:title forState:UIControlStateNormal]; [self setTitleColor:titleColor forState:UIControlStateNormal]; [self setBackgroundImage:backgroundImage forState:UIControlStateNormal]; [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; [self setImage:image forState:UIControlStateNormal]; [self setBackgroundColor:[UIColor clearColor]]; [self addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside]; } - (void)createNormalButton: (CGRect) frame title:(NSString *)title titleColor:(UIColor *)titleColor backgroundColor:(UIColor *)backgroundColor Target:(id)target Selector:(SEL)selector { [self setFrame:frame]; [self setTitle:title forState:UIControlStateNormal]; [self setTitleColor:titleColor forState:UIControlStateNormal]; [self setBackgroundColor:backgroundColor]; [self addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside]; } @end