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

使用UIDataDetectorTypes自动检测

id="iframeu2197232_0" src="http://pos.baidu.com/dcgm?rdid=2197232&dc=2&di=u2197232&dri=0&dis=0&dai=2&ps=624x830&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1467691882400&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&ari=1&dbv=0&drs=1&pcs=1280x663&pss=1280x699&cfv=22&cpl=5&chi=1&cce=true&cec=UTF-8&tlm=1467663082&rw=663&ltu=http%3A%2F%2Fworldligang.baijia.baidu.com%2Farticle%2F105149&ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DWZIAUxRXd9gMiA8urpC3K2_y3Gmj4bg7uwg9dstmp2ClCm4l6MR9mhuckCMwB0DnR6tWz_EDgTr9ICB6THZ0Nq%26wd%3D%26eqid%3Dc150f52c0002662a00000002577b2bf9&ecd=1&psr=1280x800&par=1280x724&pis=-1x-1&ccd=24&cja=true&cmi=8&col=zh-cn&cdo=-1&tcn=1467691882&qn=b014e5ff75b2b4c2&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;">

支付宝发布最新版本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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值