写一个分类 替换点击方法
#import "UIControl+Button.h"
#import <objc/objc-runtime.h>
@implementation UIControl (Button)
static int i = 0;
+ (void)load {
//runtime 进行方法替换
Method method = class_getInstanceMethod([self class], @selector(sendAction:to:forEvent:));
//create 方法
Method method2 = class_getInstanceMethod([self class], @selector(clickTimes));
method_exchangeImplementations(method, method2);
}
- (void)clickTimes {
i++;
NSLog(@"%d",i);
}