Member-only story
UITextView:Auto detect links, addresses, dates and more in iOS
1 min readOct 3, 2020
UITextView has built in support to auto detect a variety of data. The data that is able to be auto-detected currently includes:
enum {
UIDataDetectorTypePhoneNumber
UIDataDetectorTypeLink
UIDataDetectorTypeAddress
UIDataDetectorTypeCalendarEvent = 1 << 3,
UIDataDetectorTypeNone = 0,
UIDataDetectorTypeAll = NSUIntegerMax};
Enabling auto-detection
// you may add as many as you like by using the `|` operator between optionstextView.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;