开发者

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

开发者 https://www.devze.com 2023-03-11 00:31 出处:网络
I am getting a string from an API. I use a J开发者_如何学PythonSON 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 tha

I am getting a string from an API. I use a J开发者_如何学PythonSON 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.


You can do as

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

Please follow documentation for more detail.

This will detect links automatically.


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.


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

DONT MISS @property, @ synthsize

@property(nonatomic) UIDataDetectorTypes dataDetectorTypes

@synthesize dataDetectorTypes;

0

精彩评论

暂无评论...
验证码 换一张
取 消