Sameera Chathuranga
Sameera Chathuranga

Reputation: 3666

How to convert a string into a hyperlink in the iPhone SDK?

I am getting a string from an API. I use a JSON library to parse it, and after I put the string into a UITextView, I need to convert it into a hyperlink. When the user clicks on that hyperlink it should open Safari and load that site.

Upvotes: 0

Views: 1202

Answers (3)

SREE
SREE

Reputation: 11

textFiled.editable =NO; textfield.dataDetectorTypes = UIDataDetectorTypeLink;

DONT MISS @property, @ synthsize

@property(nonatomic) UIDataDetectorTypes dataDetectorTypes

@synthesize dataDetectorTypes;

Upvotes: 0

Janak Nirmal
Janak Nirmal

Reputation: 22726

You can do as

 yourTextView.editable = NO;
 yourTextView.dataDetectorTypes = UIDataDetectorTypeAll;

Please follow documentation for more detail.

This will detect links automatically.

Upvotes: 2

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31730

UITextView has the property dataDetectorTypes to show the the link as highlighted real link.

@property(nonatomic) UIDataDetectorTypes dataDetectorTypes

Set dataDetectorTypes with UIDataDetectorTypeLink.

Use it as below

 myTextView.editable = NO;
 myTextView.dataDetectorTypes = UIDataDetectorTypeLink;

From Documentation for dataDetectorTypes of UITextView

You can use this property to specify the types of data (phone numbers, http links, and so on) that should be automatically converted to clickable URLs in the text view. When clicked, the text view opens the application responsible for handling the URL type and passes it the URL.

Upvotes: 1

Related Questions