I want to create tappable texts for my terms and conditions. But there are 2 parts of it as follows:
By continuing, you are agreed to the Terms of Service and Privacy Policy.
I tried using this method, but it gave me a wrong answer. Meaning if I tapped on the terms of service, it printed Privacy Policy
or just somewhere.
@objc func tapLabel(_ gesture:UITapGestureRecognizer){
guard let text = instructionLabel.text else { return }
print("gesture : \(gesture)")
let range1 = (text as NSString).range(of: "the Terms of Service")
let range2 = (text as NSString).range(of: " and ")
let range3 = (text as NSString).range(of: "Privacy Policy")
if gesture.didTapAttributedTextInLabel(label: instructionLabel, inRange: range1) {
print("the Terms of Service")
} else if gesture.didTapAttributedTextInLabel(label: instructionLabel, inRange: range2) {
print(" and ")
} else if gesture.didTapAttributedTextInLabel(label: instructionLabel, inRange: range3){
print("Privacy Policy")
} else {
print("Somewhere else")
}
}
I'm looking forward to hearing from you. Thank you.