I'm looking to create the below image;
When a user clicks on the Log in part of the text it will call a function (present another controller for e.g)
I have code currently that uses the "Log in" as a URL however this obviously exits the app and opens safari. I want to have a #selector
for this or UITapGestureRecogniser
I think.
CURRENT CODE
class LogInTextView: UITextView {
override var selectedTextRange: UITextRange? {
get { return nil }
set {}
}
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer is UIPanGestureRecognizer {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
if let tapGestureRecognizer = gestureRecognizer as? UITapGestureRecognizer,
tapGestureRecognizer.numberOfTapsRequired == 1 {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
if let longPressGestureRecognizer = gestureRecognizer as? UILongPressGestureRecognizer,
longPressGestureRecognizer.minimumPressDuration < 0.325 {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
gestureRecognizer.isEnabled = false
return false
}
func configureAttributes() {
let textAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14, weight: .regular)]
let linkAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14, weight: .medium)]
let disclaimerText = NSMutableAttributedString(string: "Have an account already? ", attributes: textAttributes)
let linkString = NSMutableAttributedString(string: "Log in", attributes: linkAttributes)
let link = linkString.setAsLink(textToFind: "Log in", linkURL: Link.login)
if link {
self.attributedText = NSAttributedString(attributedString: linkString)
}
disclaimerText.append(linkString)
self.attributedText = disclaimerText
self.textAlignment = .left
self.dataDetectorTypes = .link
self.isScrollEnabled = false
self.isSelectable = true
self.isEditable = false
self.backgroundColor = .clear
self.textColor = .gray
self.tintColor = .systemGreen
}
override func layoutSubviews() {
super.layoutSubviews()
textContainerInset = UIEdgeInsets.zero
textContainer.lineFragmentPadding = 0
}
}