键入时在自定义 UITextField 上格式化为 Phone 数字

Formatting as Phone Number on Custom UITextField while typing

我有使用 TextFieldEffects. Now I have a different challenge that I need to use phone number formatting for some instances of TextFieldEffects but not all. At this point, I've found PhoneNumberKit 创建的自定义 UITextFields,这似乎正是我想做的。

但是,TextFieldEffects 是 UITextField that can be seen here 的实例,因此如果我在第 23 行将 UITextField 更改为 PhoneNumberTextField,它将影响所有 TextFieldEffects。

有没有一种方法可以将这两个库结合起来,让一些字段受 PhoneNumberKit 影响,但不是全部?


或者有没有更好/更方便的方法(也许是任何其他库或不使用外部库)来实现我想要实现的目标?我还有哪些其他选择?这种情况下最好的方法是什么?


为了进一步讨论,我问了另一个问题

我认为如果您查看两个库的文档和委托方法,您应该能够将两者集成。在不做所有工作的情况下,您应该使用 UITextFieldDelegate 来告诉您文本何时更改,然后使用 PhoneNumberKit 的格式化程序方法获取原始字符串并更新您的自定义 TextField 的内容。