Pregunta

Cuando intento editar textos en mi aplicación de iPhone ( UITextfield ), corrige automáticamente mi entrada.

¿Podría decirme cómo puedo deshabilitar esto?

¿Fue útil?

Solución

UITextField* f = [[UITextField alloc] init];
f.autocorrectionType = UITextAutocorrectionTypeNo;        

Otros consejos

Versión Swift

Llegué aquí buscando una versión Swift de esto:

myInput.autocorrectionType = .No

Lea también la respuesta en @MaikelS

Swift 3.0

textField.autocorrectionType = .no

Puede usar el protocolo UITextInputTraits para lograr esto:

myInput.autoCorrectionType = UITextAutocorrectionTypeNo;

Consulte aquí para más detalles.

El generador de interfaz también tiene un campo desplegable para deshabilitar esto. Como es más probable que cree campos de texto en el generador de interfaces, búsquelo allí. Puede encontrarlo en el Inspector de atributos junto a 'Corrección'.

también puede configurar esto en el guión gráfico seleccionando el 'inspector de atributos' y debajo de 'corregir' puede elegir: 'Predeterminado', 'sí' y 'no' ingrese la descripción de la imagen aquí ingrese la descripción de la imagen aquí

+ (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);
  });
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top