美文网首页
煞费苦心写label,不如加个手势爽

煞费苦心写label,不如加个手势爽

作者: Easy_VO | 来源:发表于2016-07-08 09:25 被阅读117次

    一个带下划线的UILabel,当然下划线可有可无。
    https://github.com/Easyzhan/customcustomLabel/tree/master/CustomLabelClick

    写完之后恍然大明白。给label加个手势不得了。于是应运而生。

     UILabel *labClicked                               = [[UILabel alloc] initWithFrame:CGRectMake(60, 0,  60, 60)];
    labClicked.backgroundColor                        = [UIColor redColor];
    labClicked.text                                   = @"阿三";
    labClicked.userInteractionEnabled                 = YES;
    UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTouchUpInside:)];
    
    [labClicked addGestureRecognizer:labelTapGestureRecognizer];
    [self.view addSubview:labClicked];
    

    华丽分割线------------------------

    -(void) labelTouchUpInside:(UITapGestureRecognizer *)recognizer{
    
    UILabel *label=(UILabel*)recognizer.view;
    
    NSLog(@"%@被点击了",label.text);
    }

    相关文章

      网友评论

          本文标题:煞费苦心写label,不如加个手势爽

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