开发者

How do I know if text contains URL links (UIWebView)

I have some text which might or might not contain web URLs, phone numbers, email links etc. which UIWebView automatically detects as hotspots.

Question: I want to show this text in UIWebView ONLY when there are one or more hotspots, but as plain text if it doesn't. So how can I detect this in code?

Additional Info: JavaScript code below tells how many <a href="...">...</a开发者_如何学Python> links there are. This does NOT count how many other "link" items there are. For example "Link to www.yle.fi" contains one link according to UIWebView, but zero according to JavaScript:

NSString *s = [webView stringByEvaluatingJavaScriptFromString:
                @"document.links.length"];

Still no answer to the question how to ask UIWebView how many links it has found...


You can use several regular expressions and check if the text matches those of URL/phone number/email addresses.

However, if your intention is simply let the user open a link, the UITextView is suffice.

Check the dataDetectorTypes property.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜