Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect urls in UILabel

I have a Tableview and tableview cell is customized to have a UILabel. The text in UILabel is having URLs. Is there a way to detect urls like how UITextView will enable detect URLs so that user interaction should be able to load the urls.

like image 454
Srivathsa Avatar asked Nov 13 '22 16:11

Srivathsa


1 Answers

If you just want to identify the URLs, you can use NSDataDetector with the NSTextCheckingTypeLink checking type.

If you want to draw the URLs differently, and you are targeting iOS 6, you can use an NSAttributedString to turn the URLs blue or underline them or whatever. If you're targeting an older version of iOS, you will probably want to look for some free code on the Internet to draw styled text, like OHAttributedLabel.

If you want to actually make the URLs touch-sensitive, you can add a tap gesture recognizer to the label and try to figure out which part of the string was tapped (somewhat complicated), or look for some free code on the Internet that already does it for you (like OHAttributedLabel), or just put a UITextView in the table view cell instead of a label.

like image 100
rob mayoff Avatar answered Nov 15 '22 07:11

rob mayoff