I'm wondering how to disable the inputview of a UITextfield. Setting textField.inputView = nil; or [textField setInputView:nil] in ShouldBeginEditing doesn't do anything, and using the userInteraction property removes the ability to interact with the field. Ideally, I'd like to remove both the cursor and the keyboard while still being able interact with and switch between textfield methods, using ShouldBeginEditing and ShouldEndEditing. Is there any way to accomplish this?
-
1What do you mean "switch between textfield methods"? What is it you want to do with this UITextField?Seamus Campbell– Seamus Campbell2013-08-13 17:03:13 +00:00Commented Aug 13, 2013 at 17:03
-
You want your keyborad should not appear ? is that right?Samkit Jain– Samkit Jain2013-08-13 17:18:03 +00:00Commented Aug 13, 2013 at 17:18
-
I've got a couple of UITextfields. Currently I'm using the textFieldShouldBeginEditing and textFieldShouldEndEditing to determine which field is currently active for setting things like a textfield highlight or left/right view images.DOLOisSOLO– DOLOisSOLO2013-08-13 19:32:13 +00:00Commented Aug 13, 2013 at 19:32
Add a comment
|
2 Answers
You should do this:
myTextField.inputView = UIView.new; //Empty UIView
Setting it to nil just means the default keyboard is used.
To get rid of the caret, subclass the UITextField and override caretRectForPosition:
- (CGRect) caretRectForPosition:(UITextPosition*)position
{
return CGRectZero;
}
2 Comments
DOLOisSOLO
This hides the keyboard, but setting the input view to a new view still displays the cursor in the textfield.
mattsven
You can't get rid of the cursor, not without subclassing the UITextField. I've edited my answer with how to do that.
Try this :
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO; // Hide both keyboard and blinking cursor.
}
or
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder]; // hides keyboard
}
1 Comment
DOLOisSOLO
Neither solution really work in this case. I still need the textfield to be active in order to determine what properties to set for each textfield I have in my view.