【发布时间】:2016-06-02 17:34:03
【问题描述】:
这是我在 UILabel 中显示链接的代码
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textFiled: UITextField!
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let attrStr = try! NSAttributedString(
data: "This is a link <a href='http://www.google.com'>google</a>".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil)
label.attributedText = attrStr
}
}
从图片中可以看出,它正确显示了我想要的链接,但是链接无法点击跳转到网页视图或其他。其实我需要自定义链接点击事件,我真的不知道:
- 如何获取链接的 URL。
- 如果有多个链接,我需要做什么。
感谢您首先检查此问题。
【问题讨论】: