Created
May 31, 2017 02:41
-
-
Save 5ZSQ/c91bd5f03a259ac5ab01a72f834255ed to your computer and use it in GitHub Desktop.
iOS - 为UILabel设置点击事件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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