UITextViews can automatically detect URLs and phone numbers

Quick tip: Everyone knows that when you create a UITextView in Interface Builder you can easily switch it to automatically detect URLs, but recently I was looking for the code to do this dynamically and all I code find was a 15 line REG EX. So here’s how to set text fields to dynamically detect URLs natively in UIKit:

//allows your textView to detect all types
myTextView.dataDetectorTypes = UIDataDetectorTypeAll
//or if you just want links use: UIDataDetectorTypeLink
//or just phone numbers use: UIDataDetectorTypePhoneNumber

So that’s it, nice and simple.

3 comments

  1. Resources including the one you talked about here will be really helpful to me! I will publish a link to this web page on my weblog. I am certain my visitors will find that very helpful.
    vimax

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *