iOS UIDataDetectorType 详解

 今天开发 遇到了 UIDataDetectorType,之前没了解过,今天又学习了点。详细看下面详解


还有一个 webView.detectsPhoneNumbers=NO; 去掉webView数字自动解析功能

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可以检测检测电话、网址和邮箱。效果如下:

专门写了一个iOSStrongDemo以后都在这个iOSStrongDemo里面更新内容。下载地址:iOSStrongDemo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值