iOS UITextView UIWebView 自动识别邮箱,电话,链接,UITextView的属性,代理

Xib布局textView
直接上图,必须设置不能编辑

iOS UITextView UIWebView 自动识别邮箱,电话,链接,UITextView的属性,代理_第1张图片

代码布局textView设置:

self.textView.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
    self.textView.editable = NO;

webView设置:


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

textView的部分代理操作:

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction{

    // 可以拦截电话,链接
    NSLog(@"点击了TextView的链接==%@,%@",URL.absoluteString,NSStringFromRange(characterRange));

    return YES;
}

-(BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange{

    // NSTextAttachment图片字段
    NSLog(@"点击了TextView的特殊属性==%@,%@",textAttachment.fileType,NSStringFromRange(characterRange));

    return YES;
}

// textView处于可编辑状态的时候,可以用来限制字数,监测输入的字段是否为特殊字符(@,#等)
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    NSLog(@"text==%@,range=%@,replacementText=%@",textView.text,NSStringFromRange(range),text);

    return YES;
}

- (void)textViewDidChangeSelection:(UITextView *)textView{
    // textView.selectedRange 选中的字段(弹出剪切,拷贝)  NSLog(@"selectedRange==%@",NSStringFromRange(textView.selectedRange));
}

textView的inputAccessoryView,inputView属性:

    UIView *subView = [UIView new];
    subView.frame = CGRectMake(0, 0, self.view.frame.size.width, 30);
    subView.backgroundColor = [UIColor redColor];
    self.textView.inputAccessoryView = subView; // 键盘附属物(跟随键盘移动消失,出现)
    self.textView.inputView = subView; // 键盘模式(更改键盘,类似扣扣的切换表情和功能)

textView的dataDetectorTypes属性:用来自动识别电话,邮箱,链接等等,并能够点击操作,前提就是editable=NO:

    UIDataDetectorTypePhoneNumber   // 支持电话                                     
    UIDataDetectorTypeLink         // 支持链接                                      
    UIDataDetectorTypeAddress      // 支持地址          
    UIDataDetectorTypeCalendarEvent 
    UIDataDetectorTypeShipmentTrackingNumber 
    UIDataDetectorTypeFlightNumber 
    UIDataDetectorTypeLookupSuggestion 
    UIDataDetectorTypeNone  // 不支持
    UIDataDetectorTypeAll // 支持所有

你可能感兴趣的:(Xcode-小知识点)