On iOS, a UIButton
can use addTarget
to specify a method to call when the button is tapped on, but what about UILabel
, is there something similar, or is the only option using UITapGestureRecognizer
?
Asked
Active
Viewed 2,458 times
1

nonopolarity
- 146,324
- 131
- 460
- 740
-
The question is answered here: http://stackoverflow.com/questions/3269385/programmatically-perform-an-action-on-uilabel-touchupinside – Ben-G Jul 19 '12 at 12:13
2 Answers
1
addTarget:action:forControlEvents:
is a method of UIControl class.
UIButton is a subclass of UIControl but not UILabel. So yes a tap gesture is the better way.

iSofTom
- 1,718
- 11
- 15
0
Please see this question for the answer.
UILabel inherits from UIView which inherits from UIResponder. All UIresponder objects can handle touch events.

Community
- 1
- 1

Joshua Kaden
- 1,210
- 11
- 16
-
does that mean we have to define a new class that subclasses `UILabel` and then implement `touchesBegan`? – nonopolarity Jul 19 '12 at 12:24
-
Nope! Just add code to your view controller. When following the instructions on the selected answer in the above link, note that its comments are helpful too. – Joshua Kaden Jul 19 '12 at 13:23
-
In particular, the bit about matching touch.view to your IBOutlet. – Joshua Kaden Jul 19 '12 at 17:49