I'm trying to use a dynamic mask for a text field according to the number of characters entered.
I tried to use VMaskTextField, AKMaskField and now I'm using InputMask (https://github.com/RedMadRobot/input-mask-ios) and I was only able to make one of the masks work. I want to mask as ###.###.###-## or ##.###.###/####-## but I couldn't make to change the mask while the user types. I followed two wiki posts https://github.com/RedMadRobot/input-mask-ios/wiki/Quick-Start and https://github.com/RedMadRobot/input-mask-ios/wiki/2.1-Affine-Masks.
Here my actual code:
@IBOutlet var btnEntrar: UIButton!
@IBOutlet var txtCpfCnpj: UITextField!
@IBOutlet var listener: MaskedTextFieldDelegate!
override func viewDidLoad() {
super.viewDidLoad()
listener.affinityCalculationStrategy = .prefix
listener.primaryMaskFormat = "[000].[000].[000]-[00]"
listener.affineFormats = [
"[00].[000].[000]/[0000]-[00]"
]
}
Here is the main.storyboard:
I created the listener as suggested on the wiki posts and it's now working. The field doesn't accept more characters than 11 characters, which corresponds to the first mask ([000].[000].[000]-[00])
Does anyone know how to this dynamic mask in any other way or using some framework?
Thanks