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

2015-04-03 0 869
Category  给label加扩展类 添加点击事件
//.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"

遇见资源网 objective-c Category 给label加扩展类 添加点击事件 http://www.ox520.com/16593.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务