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?

War es hilfreich?

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.

Sie können auch diese im Storyboard festgelegt durch den ‚Attribut Inspektoren‘ wählen und unter ‚Korrektur‘ können Sie wählen: ‚Standard‘, ‚Ja‘ und ‚Nein‘ „eingeben eingeben Bild Beschreibung hier

+ (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
scroll top