I have some text which might or might not contain web URLs, phone numbers, email links etc. which UIWebView automatically detects as hotspots.
我有一些文本,可能或可能不包含web url、电话号码、电子邮件链接等,UIWebView自动检测为热点。
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?
问题:我想在UIWebView中只有一个或多个热点的时候显示这个文本,但是如果没有,就像纯文本一样。那么我如何在代码中检测到这个呢?
Additional Info: JavaScript code below tells how many <a href="...">...</a> 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:
附加信息:下面的JavaScript代码告诉我们有多少
NSString *s = [webView stringByEvaluatingJavaScriptFromString:
@"document.links.length"];
Still no answer to the question how to ask UIWebView how many links it has found...
仍然没有回答如何问UIWebView它找到了多少链接…
1 个解决方案
#1
0
You can use several regular expressions and check if the text matches those of URL/phone number/email addresses.
您可以使用几个正则表达式,并检查文本是否与URL/电话号码/电子邮件地址相匹配。
However, if your intention is simply let the user open a link, the UITextView
is suffice.
但是,如果您的意图只是让用户打开一个链接,那么UITextView就足够了。
Check the dataDetectorTypes
property.
检查dataDetectorTypes财产。
#1
0
You can use several regular expressions and check if the text matches those of URL/phone number/email addresses.
您可以使用几个正则表达式,并检查文本是否与URL/电话号码/电子邮件地址相匹配。
However, if your intention is simply let the user open a link, the UITextView
is suffice.
但是,如果您的意图只是让用户打开一个链接,那么UITextView就足够了。
Check the dataDetectorTypes
property.
检查dataDetectorTypes财产。