Deaktivieren Sie die automatische Korrektur von UITextField
-
05-07-2019 - |
Frage
Wenn ich versuche, Texte in meiner iPhone-Anwendung zu bearbeiten (UITextfield
), es Auto-Korrektur meine Eingabe.
Können Sie mir mitteilen, wie kann ich das abschalten?
Lösung
UITextField* f = [[UITextField alloc] init];
f.autocorrectionType = UITextAutocorrectionTypeNo;
Andere Tipps
Swift Version
Ich landete hier für eine Swift-Version dieser Suche:
myInput.autocorrectionType = .No
Lesen Sie auch die Antwort von @MaikelS
Swift 3.0
textField.autocorrectionType = .no
Sie können das UITextInputTraits
-Protokoll verwenden, um dies zu erreichen:
myInput.autoCorrectionType = UITextAutocorrectionTypeNo;
Siehe hier für weitere Details.
Der Interface Builder hat auch ein Drop-Down-Feld diese zu deaktivieren. Wie Sie eher erstellen Textfelder in den Interface Builder sind, dann sucht es dort. Sie können es im Inspektoren Attribut neben ‚Korrektur‘ finden.
+ (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);
});
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow