1. 程式人生 > >UIWebView自動偵測電話,郵件,地址問題

UIWebView自動偵測電話,郵件,地址問題

是不是碰到過在webview中一些例如“00.12”或者“13-24”這樣的數字被識別成電話號碼,或者一個“[email protected]”被識別成郵件連結。 手生的同學可能找不到對策,其實webview中是有屬性可以控制是否偵探這些連線的,如果你什麼都不需要偵探就可以把webview.dataDetectorTypes設定成 UIDataDetectorTypeNone
以下是文件解釋 dataDetectorTypes

The types of data converted to clickable URLs in the text view.

Declaration

SWIFT

var dataDetectorTypes: UIDataDetectorTypes


OBJECTIVE-C

@property(nonatomic) UIDataDetectorTypes dataDetectorTypes

Discussion

You can use this property to specify the types of data (phone numbers, http

 links, and so on) that should be automatically converted to clickable URLs in the text view. When clicked, the text view opens the application responsible for handling the URL type and passes it the URL.

Import Statement

import UIKit

Availability

Available in iOS 3.0 and later.


UIDataDetectorTypes

Defines the types of information that can be detected in text-based content.

Declaration

OBJECTIVE-C

enum{

UIDataDetectorTypePhoneNumber = 1 << 0,

UIDataDetectorTypeLink= 1 << 1,

UIDataDetectorTypeAddress= 1 << 2,

UIDataDetectorTypeCalendarEvent= 1 << 3,

UIDataDetectorTypeNone= 0,

UIDataDetectorTypeAll= NSUIntegerMax }; typedef NSUInteger UIDataDetectorTypes;


Constants
  • UIDataDetectorTypePhoneNumber //偵探電話號碼

    Detect strings formatted as phone numbers.

    Available in iOS 3.0 and later.
  • UIDataDetectorTypeLink //偵探可能是url的字串

    Detect strings formatted as URLs. 

    Available in iOS 3.0 and later.

  • UIDataDetectorTypeAddress //偵探地址資訊

    Detect strings formatted as addresses. 

    Available in iOS 4.0 and later.
  • UIDataDetectorTypeCalendarEvent //偵探日曆時間

    Detect strings formatted as calendar events. 

    Available in iOS 4.0 and later.
  • UIDataDetectorTypeNone //不偵探任何資訊

    Do no data detection.

    Available in iOS 3.0 and later.

  • UIDataDetectorTypeAll //偵探全部

    Detect all available types of data.

    Available in iOS 3.0 and later.

Import Statement

Availability

Available in iOS 3.0 and later.