Latest 2.0.0
Homepage https://github.com/Edudjr/TLCustomMask
License MIT
Platforms ios 8.3
Authors

CI Status
Version
License
Platform

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, [email protected]

License

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

Latest podspec

{
    "name": "TLCustomMask",
    "version": "2.0.0",
    "summary": "TLCustomMask takes a string and applies a custom mask to it.",
    "description": "TLCustomMask takes a string and applies a custom mask to it.nIdeally it is used from within a TextField to apply real-time masks to text inputs.nUsage:nfunc textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {n    self.text = customMask!.formatStringWithRange(range, string: string)n    return falsen}",
    "homepage": "https://github.com/Edudjr/TLCustomMask",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Eduardo Domene Junior": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Edudjr/TLCustomMask.git",
        "tag": "2.0.0"
    },
    "platforms": {
        "ios": "8.3"
    },
    "source_files": "TLCustomMask/Classes/**/*"
}

Pin It on Pinterest

Share This