iOS webView textView禁止识别 电话号码.邮箱等

来源:互联网 发布:mac office 2011 编辑:程序博客网 时间:2024/06/17 23:52

使用UIDataDetectorTypes自动检测

<iframe id="iframeu2197232_0" src="http://pos.baidu.com/dcgm?rdid=2197232&amp;dc=2&amp;di=u2197232&amp;dri=0&amp;dis=0&amp;dai=2&amp;ps=624x830&amp;dcb=BAIDU_SSP_define&amp;dtm=BAIDU_DUP_SETJSONADSLOT&amp;dvi=0.0&amp;dci=-1&amp;dpt=none&amp;tsr=0&amp;tpr=1467691882400&amp;ti=%E4%BD%BF%E7%94%A8UIDataDetectorTypes%E8%87%AA%E5%8A%A8%E6%A3%80%E6%B5%8B--%E7%99%BE%E5%BA%A6%E7%99%BE%E5%AE%B6&amp;ari=1&amp;dbv=0&amp;drs=1&amp;pcs=1280x663&amp;pss=1280x699&amp;cfv=22&amp;cpl=5&amp;chi=1&amp;cce=true&amp;cec=UTF-8&amp;tlm=1467663082&amp;rw=663&amp;ltu=http%3A%2F%2Fworldligang.baijia.baidu.com%2Farticle%2F105149&amp;ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DWZIAUxRXd9gMiA8urpC3K2_y3Gmj4bg7uwg9dstmp2ClCm4l6MR9mhuckCMwB0DnR6tWz_EDgTr9ICB6THZ0Nq%26wd%3D%26eqid%3Dc150f52c0002662a00000002577b2bf9&amp;ecd=1&amp;psr=1280x800&amp;par=1280x724&amp;pis=-1x-1&amp;ccd=24&amp;cja=true&amp;cmi=8&amp;col=zh-cn&amp;cdo=-1&amp;tcn=1467691882&amp;qn=b014e5ff75b2b4c2&amp;tt=1467691882387.28.1225.1226" width="250" height="250" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="margin: 0px; padding: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant-caps: inherit; line-height: inherit; vertical-align: bottom; -webkit-font-smoothing: antialiased; border-width: 0px;"></iframe>

支付宝发布最新版本9.0,再一次引发一场撕逼大战。微信说支付宝抄袭了它,支付宝说微信一直都在抄袭自己。在我看来,微信和支付宝都抄袭了对方。对于大佬们的抄袭,我们也是司空见惯了。

支付宝这一次更新,真是赚足了眼球,估计这也是支付宝的推广策略。就是要造势,造势有利于品牌推广。传播速度可想而知,似乎一夜之间都在谈论支付宝和微信。

至于支付宝和微信谁能打过谁,我们拭目以待。

上一篇文章 UIWebView用法详解及代码分享 里面提到:

webView.dataDetectorTypes=UIDataDetectorTypePhoneNumber;//自动检测网页上的电话号码,单击可以拨打

接下来我们来简单讲一下,使用UIDataDetectorTypes自动检测电话、网址和邮箱。我们先来看看UIDataDetectorTypes有哪些枚举值。

UIDataDetectorTypes的枚举值

typedefNS_OPTIONS(NSUInteger,UIDataDetectorTypes){

UIDataDetectorTypePhoneNumber  =1<<0,         //Phonenumberdetection

UIDataDetectorTypeLink         =1<<1,         //URLdetection   

#if__IPHONE_4_0<=__IPHONE_OS_VERSION_MAX_ALLOWED

UIDataDetectorTypeAddress      =1<<2,         //Streetaddressdetection

UIDataDetectorTypeCalendarEvent=1<<3,         //Eventdetection

#endif   

UIDataDetectorTypeNone         =0,              //Nodetectionatall

UIDataDetectorTypeAll          =NSUIntegerMax   //Alltypes

};

NS_OPTIONS一般用来定义位移相关操作的枚举值。UIDataDetectorTypeAddress,UIDataDetectorTypeCalendarEvent不在我们考虑的范围了。

UIWebView有dataDetectorTypes属性,UITextView也有dataDetectorTypes属性。我们来UITextView来举例。

创建UITextView

UITextView*textView=[[UITextViewalloc]initWithFrame:self.view.bounds];

textView.font=[UIFontsystemFontOfSize:20];

textView.editable=NO;

textView.text=@"\r\n我的手机号不是:13888888888\r\n\r\n"

"我的博客刚刚在线网址:www.xxxxxx.com\r\n\r\n"

"我的邮箱:worldligang@163.com\r\n\r\n";

[self.viewaddSubview:textView];

运行起来看一下:

可以看出来就是一个简单的文本,电话号码,网址和邮箱都没有检测出来。下面我们来看看dataDetectorTypes作用。

UIDataDetectorTypePhoneNumber检测电话

textView.dataDetectorTypes=UIDataDetectorTypePhoneNumber;

设置textView.dataDetectorTypes的属性,即可检测文本中的电话。效果如下所示:

UIDataDetectorTypeLink检测网址和邮箱

textView.dataDetectorTypes=UIDataDetectorTypeLink;

UIDataDetectorTypeLink检测网址和邮箱的。点击网址会跳转到相应的网页,点击邮箱可以调用系统的发邮件。

UIDataDetectorTypeAll检测电话、网址和邮箱

textView.dataDetectorTypes=UIDataDetectorTypeAll;

UIDataDetectorTypeAll可以检测检测电话、网址和邮箱。效果如下:

0 0
原创粉丝点击