答案 0 :(得分:0)
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")
}
}