如何让UILabel回应? [英] How to get UILabel to respond to tap?

查看:85
本文介绍了如何让UILabel回应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我可以比UITextField更快地创建UILabel,并且我计划在大多数时间使用UILabel来处理我的数据显示应用程序。

I have discovered that I can create UILabel much faster than UITextField and I plan to use UILabel most of the time for my data display app.

要做多久尽管如此,我希望让用户点击UILabel并让我的回调响应。这可能吗?

To make a long story short though, I wish to let the user tap on a UILabel and have my callback respond to that. Is that possible?

谢谢。

推荐答案

你可以添加一个您的UILabel的 UITapGestureRecognizer 实例。

You can add a UITapGestureRecognizer instance to your UILabel.

例如:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[myLabel addGestureRecognizer:tapGestureRecognizer];
myLabel.userInteractionEnabled = YES;

这篇关于如何让UILabel回应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆