0
votes

Supprimer les espaces blancs de la fin d'un champ de texte à Swift

J'ai un email Textfield qui est livré lors de l'enregistrement de l'utilisateur. Si j'ajoute un espace à la fin de l'email Je ne parviens pas à enregistrer l'utilisateur. Comment puis-je supprimer l'espace à la fin? Par exemple: abc@gmail.com+Space Cet espace doit être supprimé.


0 commentaires

3 Réponses :


0
votes

Faites comme ceci:

func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool {
       if range.location == 0 && string == " " {
           return false
       }
       return true
 }


0 commentaires

0
votes
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    let cs = Character(" ")
    let filtered = string.components(separatedBy: cs).joined(separator: "")

    return (string == filtered)
}

0 commentaires

0
votes

Utilisez cette méthode courante dans votre classe d'assistrations: strong>

Description: P>

let string = trimWhiteSpaceNew(str: textfield.text)


0 commentaires