I am using a UITextField
with a UIPickerView
for its inputView
, so that when the user taps the text field, a picker is summoned for them to select an option from.
Nearly everything works, but I have one problem: the cursor still flashes in the text field when it is active, which is ugly and inappropriate, since the user is not expected to type into the field and is not presented with a keyboard. I know I could hackily solve this by setting editing
to NO
on the text field and tracking touches on it, or by replacing it with a custom-styled button, and summoning the picker via code. However, I want to use the UITextFieldDelegate
methods for all the event handling on the text field and hacks such as replacing the text field with a button do not permit this approach.
How can I simply hide the cursor on the UITextField
instead?
You can just clear the textfield's tintColor
Swift 3.0
Answer provided by the OP, copied from the question body to help clean up the ever growing tail of unanswered questions.
I found another solution: subclass
UIButton
and override these methodsNow the button, as a
UIResponder
, have a similar behavior thanUITextField
and an implementation pretty straightforward.You might also want to stop the user from selecting, copying or pasting any text so that the only text input comes from the picker view.
http://b2cloud.com.au/tutorial/disabling-the-caret-and-text-entry-in-uitextfields/
As of iOS 7 you can now just set the
tintColor = [UIColor clearColor]
on the textField and the caret will disappear.If you want to hide cursor, you can easily use this! It worked for me..
Swift 3 version of Net's post