TLCustomMask
Example
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:
How to Use
CustomMask takes a string and returns it with the matching pattern. Usualy, it is used inside the shouldChangeCharactersInRange method
Step 1 - Import
import TLCustomMask
Step 2 - Instantiate
var customMask = TLCustomMask()
Step 3 - Give it a pattern
customMask.formattingPattern = "$$.$$/$$-$"
Step 4 - Present
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
}
}
Step 5 - Profit
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]
Installation
TLCustomMask is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "TLCustomMask"
Author
Eduardo Domene Junior, [email protected]
License
TLCustomMask is available under the MIT license. See the LICENSE file for more info.