This component is not supported anymore. Instead, use the MaskedUITextField as it is newer and allows creating much more flexible masks. If you just need the mask formatter decoupled from UIKit, check MaskedFormatter.
To run the example project, clone the repo, and run pod install from the Example directory first.
Numeric mask example:
Characters mask example:
Mixed mask example:
CustomMask takes a string and returns it with the matching pattern. Usualy, it is used inside the shouldChangeCharactersInRange method
import TLCustomMaskvar customMask = TLCustomMask()customMask.formattingPattern = "$$.$$/$$-$"If you just want to format a string and present it to the user, do:
yourTextField.text = customMask.formatString(string: "1234567")If you want real time formatting, do:
extension YourViewController: UITextFieldDelegate{
func textField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> Bool {
yourTextField.text = customMask.formatStringWithRange(range: range, string: string)
return false
}
}Now you are ready to go!
Alternatively, you can instantiate it with a pattern already:
var customMask = TLCustomMask(formattingPattern: "$$$-$$")Use $ for digits
Use * for characters [a-zA-Z]
TLCustomMask is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "TLCustomMask"Eduardo Domene Junior, eduardo.djr@hotmail.com
TLCustomMask is available under the MIT license. See the LICENSE file for more info.


