Krelborn / KILabel

A simple to use drop in replacement for UILabel for iOS 7 and above that highlights links such as URLs, twitter style usernames and hashtags and makes them touchable.
MIT License
470 stars 133 forks source link

Add support for phone numbers, and for highlighting only pre-tagged matches #36

Open granoff opened 8 years ago

granoff commented 8 years ago

Phone number support is provided using the phone number data detector. Some refactoring of existing code streamlined this enhancement.

There is also the addition of a flag that prevents matches that do not already have a link attribute from being decorated and made tappable. I needed this because the phone number data detector will match text like "phone number 508-555-1234" rather than just "508-555-1234" and I wanted patterns like the latter highlighted. Similarly, words like "toll free" are also picked up if they precede a phone number.

I had already written code in my own project to find and decorate just the phone numbers, so it made sense to add support to this class to honor pre-set links and their text and ignore matches without a pre-set link.

The use case for the latter part is a string with several phone numbers, not all of which are callable (e.g. a FAX number). By pre-decorating the callable numbers only, and setting the new ignoreMatchesWithoutLinkAttribute flag, only those matching text ranges already having a link are decorated by the class.

I also updated the demo app.

jonataspc commented 8 years ago

Great job man! That was exacty what I was looking for.