Category 给label加扩展类 添加点击事件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

//.h文件
#import <UIKit/UIKit.h>

@interface UILabel (hanhan)

- (void)dianjishijian:(id)target action:(SEL)action;

@end



//.m文件

#import "UILabel+hanhan.h"

@implementation UILabel (hanhan)


- (void)dianjishijian:(id)target action:(SEL)action{
    self.userInteractionEnabled  = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:target action:action];
    [self addGestureRecognizer:tap];
  
    
}
@end
//使用
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 100, 100)];
    [label dianjishijian:self action:@selector(btn)];
    [self.view addSubview:label];
//别忘了导头文件  #import "UILabel+hanhan.h"