问题描述
我有一堆通过代码添加的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上执行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!