gpt4 book ai didi

ios - 如何在 Swift 中制作一个可点击的 UITextView?

转载 作者:行者123 更新时间:2023-11-28 23:33:04 29 4
gpt4 key购买 nike

有没有办法创建一个可点击单词的UITextView

当我单击该单词时,该单词将突出显示。请引用下图。

effect

最佳答案

     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")
}
}

关于ios - 如何在 Swift 中制作一个可点击的 UITextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55865442/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com