美文网首页
iOS 给label添加点击事件

iOS 给label添加点击事件

作者: Lee坚武 | 来源:发表于2019-12-09 14:16 被阅读0次

// 1. 创建一个点击事件,点击时触发labelClick方法
UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick)];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];

// 2. 将点击事件添加到label上    

[label addGestureRecognizer:labelTapGestureRecognizer];

label.userInteractionEnabled = YES; // 可以理解为设置label可被点击//

  1. 在此方法中设置点击label后要触发的操作
  • (void)labelClick {

}

相关文章

网友评论

      本文标题:iOS 给label添加点击事件

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