Input-mask-ios: ¿Cómo aplicar la máscara al texto existente?

Creado en 4 oct. 2017  ·  2Comentarios  ·  Fuente: RedMadRobot/input-mask-ios

Hola,

¿Qué he definido máscara y delegado, y quiero establecer un texto predefinido en un campo de texto?

Cuando lo hago - myTextField.txt = "12345678" no se aplica la máscara.

question

Comentario más útil

Hola @beltik ,
Gracias por tu pregunta.

En nuestro README, hay un código de muestra en el párrafo Simple UITextField for the phone numbers :

class ViewController: UIViewController, MaskedTextFieldDelegateListener {

    var maskedDelegate: MaskedTextFieldDelegate!

    <strong i="11">@IBOutlet</strong> weak var field: UITextField!

    open override func viewDidLoad() {
        maskedDelegate = MaskedTextFieldDelegate(format: "{+7} ([000]) [000] [00] [00]")
        maskedDelegate.listener = self

        field.delegate = maskedDelegate

        maskedDelegate.put(text: "+7 123", into: field)
    }

    open func textField(
        _ textField: UITextField, 
        didFillMandatoryCharacters complete: Bool,
        didExtractValue value: String
    ) {
        print(value)
    }

}

La línea que podría considerar usar para poner texto predefinido en el campo es

maskedDelegate.put(text: "+7 123", into: field)

- En términos generales, este método usa la misma instancia Mask como si fuera un usuario típico escribiendo, pero pasa el texto mediante programación.

Todos 2 comentarios

Hola @beltik ,
Gracias por tu pregunta.

En nuestro README, hay un código de muestra en el párrafo Simple UITextField for the phone numbers :

class ViewController: UIViewController, MaskedTextFieldDelegateListener {

    var maskedDelegate: MaskedTextFieldDelegate!

    <strong i="11">@IBOutlet</strong> weak var field: UITextField!

    open override func viewDidLoad() {
        maskedDelegate = MaskedTextFieldDelegate(format: "{+7} ([000]) [000] [00] [00]")
        maskedDelegate.listener = self

        field.delegate = maskedDelegate

        maskedDelegate.put(text: "+7 123", into: field)
    }

    open func textField(
        _ textField: UITextField, 
        didFillMandatoryCharacters complete: Bool,
        didExtractValue value: String
    ) {
        print(value)
    }

}

La línea que podría considerar usar para poner texto predefinido en el campo es

maskedDelegate.put(text: "+7 123", into: field)

- En términos generales, este método usa la misma instancia Mask como si fuera un usuario típico escribiendo, pero pasa el texto mediante programación.

Gracias, la tarea puede estar cerrada. Funcionó.

¿Fue útil esta página
0 / 5 - 0 calificaciones

Temas relacionados

osterlind picture osterlind  ·  3Comentarios

LinusGeffarth picture LinusGeffarth  ·  4Comentarios

TikhonovAlexander picture TikhonovAlexander  ·  3Comentarios

caioremedio picture caioremedio  ·  6Comentarios

KompoD picture KompoD  ·  5Comentarios