美文网首页
UILabel 添加点击事件

UILabel 添加点击事件

作者: 第一梯队利群 | 来源:发表于2019-08-24 12:34 被阅读0次

    默认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);
       
    }
    

    相关文章

      网友评论

          本文标题:UILabel 添加点击事件

          本文链接:https://www.haomeiwen.com/subject/mjofectx.html