以编程方式在UILabel touchUpInside上执行操作? [英] Programmatically perform an action on UILabel touchUpInside?

查看:60
本文介绍了以编程方式在UILabel touchUpInside上执行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆通过代码添加的UILabel,并且如果用户的手指在内部触摸,我想为每个UILabel执行特定的操作(类似于IB中的UIButton的touchUpInside).最好的方法是什么?

I have a bunch of UILabels that I add through code and I want to perform a specific action for each if the user's finger touches up inside (much like UIButton's touchUpInside in IB). What is the best way of doing this?

推荐答案

最简单的方法可能是使用UIButton代替UILabel.自定义UIButton没有边框,看起来像普通标签,但可以为您处理事件跟踪.

The easiest way is probably to use UIButton instead of UILabel. A custom UIButton has no border and can look like a plain label, but handles the event tracking for you.

否则,您必须派生自UILabel并实现UIResponder调用以进行触摸处理.

Otherwise, you must derive from UILabel and implement the UIResponder calls for touch handling.

这篇关于以编程方式在UILabel touchUpInside上执行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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