Как сделать слово кликабельным UITextView в Swift? - PullRequest
0 голосов
/ 26 апреля 2019

Есть ли способ создать UITextView со словом clickable.

Когда я нажму на слово, слово будет выделено.Пожалуйста, обратитесь к изображению ниже.

effect

1 Ответ

0 голосов
/ 26 апреля 2019
     let textTest = "I have read and agree with the Privacy Policy & Terms and Conditions"

    let tap = UITapGestureRecognizer(target: self, action: #selector(self.tapLabel))

    textTest.isUserInteractionEnabled = true
    textTest.addGestureRecognizer(tap)

   @IBAction func tapLabel(gesture: UITapGestureRecognizer) {

    let text = (textTest)!
    let termsRange = (text as NSString).range(of: "Terms and Conditions")
    let privacyRange = (text as NSString).range(of: "Privacy Policy")

    if gesture.didTapAttributedTextInLabel(label: attributeLabel, inRange: termsRange) {
        print("Tapped terms")
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "TermsConditionViewController") as! TermsConditionViewController
        self.navigationController?.pushViewController(vc, animated: true)
    } else if gesture.didTapAttributedTextInLabel(label: attributeLabel, inRange: privacyRange) {
        print("Tapped privacy")
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "PrivacyPolicyViewController") as! PrivacyPolicyViewController
        self.navigationController?.pushViewController(vc, animated: true)
    } else {
        print("Tapped none")
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...