一. 代码
-
.h文件内容
#import <UIKit/UIKit.h>
typedef void (^ButtonBlock)(UIButton *); @interface BlockButton : UIButton - (void)addTapBlock:(ButtonBlock)block; @end
-
.m文件内容
#import "BlockButton.h"
@interface BlockButton() @property(nonatomic,copy) ButtonBlock block; @end @implementation BlockButton - (void)addTapBlock:(ButtonBlock)block { _block = block; [self addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } - (void)buttonAction:(UIButton *)button { _block(button); } @end