Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel + touchDown

Tags:

xcode

iphone

ios4

Is it possible to implement touchdown for UILabel?


1 Answers

UILabel is a subclass of UIView, which is itself a subclass of UIResponder; therefore, it’s definitely possible to make a label that responds to touches. Just make a new subclass of UILabel and implement the following method(s):

– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:

So, if you wanted something to happen when touches started, you’d do it in -touchesBegan:withEvent:.

If creating a new subclass is too heavy-handed for you, then I’d suggest doing as @JustSid suggests and using a UIButton for the task.

like image 93
Jeff Kelley Avatar answered Aug 13 '26 03:08

Jeff Kelley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!