identify URL in text view and show in safari iphone
I want to identify the URLs/https in my textview and display it in some other color. Also when Click on that it should ope开发者_开发问答n in Safari. How can I do that ? Any Sample Application Code available ? I do not want to include Three20.
You can enable dataDetectorTypes with your UITextView so URLs (and other common links) are detected and automatically linked to their default application.
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectZero];
text.dataDetectorTypes = UIDataDetectorTypeLink; // see below for other options
See Apple documentation for other dataDetectorTypes options here https://developer.apple.com/library/content/qa/qa1495/_index.html
From iOS7 and later now it becomes more easy to detect link in UITextView
.
UITextView *txtView=[[UITextView alloc]initWithFrame:CGRectMake(0, 10, 320, 500)];
txtView.delegate=self;
txtView.dataDetectorTypes = UIDataDetectorTypeLink;
Implement this delegate method:
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
// do what ever you want
return YES;
}
精彩评论