UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
// 1.创建一个点击事件,点击时触发labelClick方法
UITapGestureRecognizer *labelTapGestureRecognizer =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick)];
// 2. 将点击事件添加到label上
label addGestureRecognizer:labelTapGestureRecognizer];
// 3. 设置label可被点击
label.userInteractionEnabled = YES;
// 4. 在此方法中设置点击label后要触发的操作
- (void)labelClick {
}
IOS中实现Lable点击事件
最新推荐文章于 2024-06-12 11:18:16 发布