Skip to content

Edudjr/TLCustomMask

Repository files navigation

TLCustomMask

CI Status Version License Platform

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.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Numeric mask example:

image

Characters mask example:

image

Mixed mask example:

image

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, eduardo.djr@hotmail.com

License

TLCustomMask is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors