Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get UILabel to respond to tap?

Tags:

ios

uilabel

ipad

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.

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?

Thanks.

like image 886
Happy Avatar asked Aug 22 '11 22:08

Happy


People also ask

How do you make UILabel clickable?

To make UILabel clickable you will need to enable user interaction for it. To enable user interaction for UILabel simply set the isUserInteractionEnabled property to true.


1 Answers

You can add a UITapGestureRecognizer instance to your UILabel.

For example:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)]; tapGestureRecognizer.numberOfTapsRequired = 1; [myLabel addGestureRecognizer:tapGestureRecognizer]; myLabel.userInteractionEnabled = YES; 
like image 154
pythonquick Avatar answered Oct 06 '22 00:10

pythonquick