iosswifttextfieldrightview

Tap on rightView of textField when this textField be disabled in Swift?


I have a textField like this:

@IBOutlet weak var titleTextField:UITextField!

Then I add image beside this textField:

titleTextField.rightView = titleImg

with titleImg is a imageView. I used UITapGestureRecognizer to tap on titleImg imageView, it working fine.

And finally, I set:

titleTextField.userInteractionEnabled = false 

but with this, my titleImg can't be tap. It mean I want disable titleTextField, but user can tap on titleImg. How to resolve it?


Solution

  • Your titleImg is added to titleTextField, so on disabling user interaction of text field, it won't allow image view to take tap. You should remove titleImg from titleTextField and use separate UIButton with image added for taking tap while text field is disabled.