How to make an expression clickable on iOS?

2020-02-29 10:20发布

问题:

I am writing a Twitter type client. I want stuff like @ and # clickable. When I click on it, I want it to do some sort of IBAction. I found this for OSX:

http://flyosity.com/mac-os-x/clickable-tweet-links-hashtags-usernames-in-a-custom-nstextview.php

This is along the lines of what I want to accomplish. Anything for iOS that is of this caliber?

回答1:

Look at this page http://furbo.org/2008/10/07/fancy-uilabels/



回答2:

The best dropin solution I've found was this: https://github.com/SebastienThiebaud/STTweetLabel Clean and simple.



回答3:

You can make any properly formatted URLs appear as blue underlined active links in a UITextView with the following code (in say viewDidLoad)

self.myTextView.editable = NO;
self.myTextView.dataDetectorTypes = UIDataDetectorTypeLink;

Search for "Technical Q&A QA1495" in Xcode's Documentation and API Reference.



回答4:

Just off the top of my head, I guess you could achieve it by using a UIWebView to display the content (which you have linkified, as per the "2: Finding The Interesting Parts" part of the blog post).

If you then prefix the hashtag links with a custom url scheme, like myappopenshashtags://, and register that url scheme for your app, you should be able to open your hashtags in whatever way you please.