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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you just want to identify the URLs, you can use
NSDataDetectorwith theNSTextCheckingTypeLinkchecking type.If you want to draw the URLs differently, and you are targeting iOS 6, you can use an
NSAttributedStringto 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, likeOHAttributedLabel.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 aUITextViewin the table view cell instead of a label.