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

iOS 给label添加点击事件

作者: 潇岩 | 来源:发表于2018-05-03 20:41 被阅读58次

// 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可被点击// 

3. 在此方法中设置点击label后要触发的操作

- (void)labelClick {

}

相关文章

网友评论

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

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