Formatting Phone number in Swift

前端 未结 12 1893
天命终不由人
天命终不由人 2020-12-02 09:36

I\'m formatting my textfiled text once the user start typing the phone number into this format type 0 (555) 444 66 77 and it is working fine but once I get the

12条回答
  •  猫巷女王i
    2020-12-02 09:56

    You can use this library https://github.com/luximetr/AnyFormatKit

    Example

    let textInputController = TextInputController()
    
    let textInput = TextInputField() // or TextInputView or any TextInput
    textInputController.textInput = textInput // setting textInput
    
    let formatter = TextInputFormatter(textPattern: "### (###) ###-##-##", prefix: "+12")
    textInputController.formatter = formatter // setting formatter
    

    Just set your textField to this textInputController and it will format text with pattern, that you set.

提交回复
热议问题