Reputation: 10069
In my app i am using UITextView to display three lines. In that i need to add link for certain text. I am searched in google and SO, but i couldn't found the exact solution for my problem.
I Tried this but its not working
NSString *testString = @"This will go to <a href = \"http://www.google.com\">Google</a>";
[webview loadHTMLString:testString baseURL:baseURL];
[lblLinksTitle setText:testString];
I want Google as clickable text which have to open in safari browser. May be its simple. As i am new to iOS i couldn't figure out to do this.
Thanks for your help guys.
Much appreciated.
Upvotes: 1
Views: 1171
Reputation: 3547
Just use UIWebView, don't use UiTextView
NSString *testString = @"This will go to <a href = \"http://www.google.com\">Google</a>";
[webview loadHTMLString:testString baseURL:nil];
webview.delegate=self;
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSString * requestString=[[request URL] absoluteString];
//NSLog(@"%@ is requestString from clicking",requestString );
if ([[[request URL] absoluteString] hasPrefix:@"http://www.google"]) {
[[UIApplication sharedApplication] openURL:[request URL]];
}
return TRUE;
}
Upvotes: 1
Reputation: 9942
Try using this:
lblLinksTitle.editable = NO;
lblLinksTitle.dataDetectorTypes = UIDataDetectorTypeLink;
lblLinksTitle.text = testString;
Upvotes: 1