您的位置:首页 > 其它

Runtime_实现计算一个Button被点击次数

2016-02-08 22:02 190 查看
写一个分类  替换点击方法

#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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  RunTime