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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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:
Try this :
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { return NO; // Hide both keyboard and blinking cursor. } or
-(void)textFieldDidBeginEditing:(UITextField *)textField{ [textField resignFirstResponder]; // hides keyboard }