//.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"
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....