Skip to content

Instantly share code, notes, and snippets.

@5ZSQ
Created May 31, 2017 02:41
Show Gist options
  • Save 5ZSQ/c91bd5f03a259ac5ab01a72f834255ed to your computer and use it in GitHub Desktop.
Save 5ZSQ/c91bd5f03a259ac5ab01a72f834255ed to your computer and use it in GitHub Desktop.
iOS - 为UILabel设置点击事件
// 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 {
// be click ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment