ios 禁用 UITextField 的自动更正
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/827310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable auto correction of UITextField
提问by ebaccount
When I try to edit texts in my iPhone application (UITextfield
), it auto-corrects my input.
当我尝试在 iPhone 应用程序 ( UITextfield
) 中编辑文本时,它会自动更正我的输入。
Could you let me know how can I disable this?
你能告诉我如何禁用它吗?
回答by George Armhold
UITextField* f = [[UITextField alloc] init];
f.autocorrectionType = UITextAutocorrectionTypeNo;
回答by Dan Beaulieu
回答by Jonas
回答by MaikelS
The Interface Builder also has a dropdown field to disable this. As you're more likely to create textfields in the interface builder, look for it there. You can find it in the Attributes Inspector next to 'Correction'.
Interface Builder 也有一个下拉字段来禁用它。由于您更有可能在界面构建器中创建文本字段,因此请在那里查找。您可以在“更正”旁边的属性检查器中找到它。
回答by gutte
回答by Alok Singh
+ (void)disableAutoCorrectionsForTextfieldsAndTextViewGlobally {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
struct objc_method_description autocorrectionTypeMethodDescription =
protocol_getMethodDescription(@protocol(UITextInputTraits),
@selector(autocorrectionType), NO, YES);
IMP noAutocorrectionTypeIMP_TEXT_FIELD =
imp_implementationWithBlock(^(UITextField *_self) {
return UITextAutocorrectionTypeNo;
});
IMP noAutocorrectionTypeIMP_TEXT_VIEW =
imp_implementationWithBlock(^(UITextView *_self) {
return UITextAutocorrectionTypeNo;
});
class_replaceMethod([UITextField class], @selector(autocorrectionType),
noAutocorrectionTypeIMP_TEXT_FIELD,
autocorrectionTypeMethodDescription.types);
class_replaceMethod([UITextView class], @selector(autocorrectionType),
noAutocorrectionTypeIMP_TEXT_VIEW,
autocorrectionTypeMethodDescription.types);
});
}