我正在尝试使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;

希望能帮助你。

10-08 06:10