Auto Detect Links Addresses Dates and more
suggest changeUITextView has built in support to auto detect a variety of data. The data that is able to be auto-detected currently includes:
enum {
UIDataDetectorTypePhoneNumber = 1 << 0,
UIDataDetectorTypeLink = 1 << 1,
UIDataDetectorTypeAddress = 1 << 2,
UIDataDetectorTypeCalendarEvent = 1 << 3,
UIDataDetectorTypeNone = 0,
UIDataDetectorTypeAll = NSUIntegerMax
};
Enabling auto-detection
// Combine options with the `|` operator.
textView.dataDetectorTypes = (UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber);
If enabled, the text will appear as a hyperlink on the UITextView
Clickable data
To allow the link to be clicked (which will result in different actions depending on the data type) you must ensure that the UITextView is selectable but not editable and that user interaction is enabled
textView.editable = NO;
textView.selectable = YES;
textView.userInteractionEnabled = YES; // YES by default
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents