禁用 UITextfield 的键盘 [英] Disable Keyboard for UITextfield
问题描述
我想知道如何禁用 UITextfield 的输入视图.在 ShouldBeginEditing 中设置 textField.inputView = nil;
或 [textField setInputView:nil]
不会做任何事情,而使用 userInteraction
属性会删除与领域互动的能力.理想情况下,我想同时移除光标和键盘,同时仍然能够使用 ShouldBeginEditing 和 ShouldEndEditing 与文本字段方法进行交互和切换.有没有办法做到这一点?
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?
推荐答案
你应该这样做:
myTextField.inputView = UIView.new; //Empty UIView
将其设置为 nil
仅表示使用默认键盘.
Setting it to nil
just means the default keyboard is used.
要去掉插入符号,将 UITextField 子类化并覆盖 caretRectForPosition
:
To get rid of the caret, subclass the UITextField and override caretRectForPosition
:
- (CGRect) caretRectForPosition:(UITextPosition*)position
{
return CGRectZero;
}
这篇关于禁用 UITextfield 的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!