I have been searching this for hours but I've failed. I probably don't even know what I should be looking for.
Many applications have text and in this text are web hyperlinks in rounded rect. When I click them UIWebView
opens. What puzzles me is that they often have custom links, for example if words starts with # it is also clickable and the application responds by opening another view. How can I do that? Is it possible with UILabel
or do I need UITextView
or something else?
Drop-in solution as a category on
UILabel
(this assumes yourUILabel
uses an attributed string with someNSLinkAttributeName
attributes in it):The UIButtonTypeCustom is a clickable label if you don't set any images for it.
Here’s a Swift implementation that is about as minimal as possible that also includes touch feedback. Caveats:
"\u{a0}"
).link
keys.
I created UILabel subclass named ResponsiveLabel which is based on textkit API introduced in iOS 7. It uses the same approach suggested by NAlexN. It provides flexibility to specify a pattern to search in the text. One can specify styles to be applied to those patterns as well as action to be performed on tapping the patterns.
If you want to make a string clickable, you can do this way. This code applies attributes to each occurrence of the string "text".
Here is example code to hyperlink UILabel: Source:http://sickprogrammersarea.blogspot.in/2014/03/adding-links-to-uilabel.html