[英]How to make tappable NSAttributedString Move To Another ViewController Swift
[英]How to make tappable links in NSAttributedString
我正在尝试使UITextView内容的某些部分可点击。 这是我的代码:
class ViewController: UIViewController,UITextViewDelegate {
@IBOutlet weak var definition:UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//self.loadHTML()
self.makeList()
}
func makeList(){
definition.delegate = self
let attributedString = NSMutableAttributedString(string: "Want to learn iOS? You should visit the best source of free iOS tutorials!")
attributedString.addAttribute(NSLinkAttributeName, value: "https://www.hackingwithswift.com", range: NSRange(location: 0, length: 5))
definition.attributedText = attributedString
}
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
UIApplication.sharedApplication().openURL(URL)
return true
}
}
一些如何这是行不通的。 你能帮我所缺少的吗?
definition.editable = false;
definition.delegate = self;
希望可以帮到您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.