默认UILabel 是不支持点击事件的,实现如下:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, listV.frame.size.width - 60, listV.frame.size.height)];
label.userInteractionEnabled=YES;
UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTouchUpInside:)];
[label addGestureRecognizer:labelTapGestureRecognizer];
-(void) labelTouchUpInside:(UITapGestureRecognizer *)recognizer{
UILabel *label=(UILabel*)recognizer.view;
NSLog(@"%@被点击了",label.text);
}
网友评论