如何在 NSAttributedString 中創建可點擊的鏈接? - How can I make a clickable link in an NSAttributedString?

問題:

It's trivial to make hyperlinks clickable in a UITextView .UITextView中使超鏈接可點擊是微不足道的。 You just set the "detect links" checkbox on the view in IB, and it detects HTTP links and turns them into hyperlinks.您只需在 IB 中的視圖上設置“檢測鏈接”複選框,它就會檢測 HTTP 鏈接並將它們轉換爲超鏈接。

However, that still means that what the user sees is the "raw" link.但是,這仍然意味着用戶看到的是“原始”鏈接。 RTF files and HTML both allow you to set up a user-readable string with a link "behind" it. RTF 文件和 HTML 都允許您設置用戶可讀的字符串,並在其“後面”帶有鏈接。

It's easy to install attributed text into a text view (or a UILabel or UITextField , for that matter.) However, when that attributed text includes a link, it is not clickable.將屬性文本安裝到文本視圖(或UILabelUITextField ,就此而言)很容易。但是,當該屬性文本包含鏈接時,它是不可點擊的。

Is there a way to make user-readable text clickable in a UITextView , UILabel or UITextField ?有沒有辦法讓用戶可讀的文本在UITextViewUILabelUITextField可點擊?

The markup is different on SO, but here is the general idea. SO 上的標記有所不同,但這是總體思路。 What I want is text like this:我想要的是這樣的文字:

This morph was generated with Face Dancer , Click to view in the app store.這個變形是用Face Dancer生成的,點擊應用商店查看。

The only thing I can get is this:我唯一能得到的是:

This morph was generated with Face Dancer, Click on http://example.com/facedancer to view in the app store.這個變形是用Face Dancer生成的,點擊http://example.com/facedancer在應用商店查看。


解決方案:

參考一: https://stackoom.com/question/1SktU
參考二: How can I make a clickable link in an NSAttributedString?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章