简体   繁体   中英

Tap on the tex in UILabel

I have a UILabel. I would to detect a tap only on the text of this label.

For example, I have a UILabel very large with some text in the center.

Is possible this? I can't add/use other UILabel or components.

Add UITapGestureRecongizer on the label:

UITapGestureRecognizer *labelTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionForTap:)];
[yourLabel addGestureRecognizer:labelTap];

To make the tap active only on the text, set the uilabel text and then call:

[yourLabel sizeToFit] 

in order to make the UILabel frame as big as the text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM