-
Notifications
You must be signed in to change notification settings - Fork 96
Home
Egor Taflanidi edited this page Jul 28, 2023
·
14 revisions
- For a quick start, scroll down
- Syntax: learn how to compose your masks
- Text field listeners: learn more about available text field listener (delegate) classes
- Phones and country codes: more info about the international phone number formats support
- Tail placeholder: implement a placeholder that is always visible & guides user input
- Multiple masks & affinity: you can have several formats associated with a single text field; this is a deeper look into how the library can decide between them
Advanced reading:
- Custom notations: discover how to extend the mask syntax
- Text field listener internals: read in detail about the logic behind listening to text changes
- Mask, State Machine & Compiler: find out about the main library engine
Swift Package Manager is the preferred way.
- Open project root settings → Package Dependencies
- Click ➕Add Package Dependency
- Click 🔍Search or Enter Package URL
- Insert
https://github.com/RedMadRobot/input-mask-ios
- Click Add Package
- Wait for the package resolution, choose target, boom, done
Import the library:
import InputMask
Configure the text field:
let inputListener = MaskedTextInputListener(primaryFormat: "+380 ([00]) [000]-[00]-[00]")
textField.delegate = inputListener // remember that delegates are weak references
Done. Build, Run & Enjoy.
In order to attach our library to your UITextField
you may simply wire up a listener directly within the layout.
- Open the scene that contains the
UITextField
in question - Open Library
⌘⇧L
→ findNSObject
→ drop it onto the Scene (the left hierarchy view) - In the Identity Inspector select a custom class for this object:
MaskedTextInputListener
- In the Attributes Inspector fill in the
Primary Mask Format
:+380 ([00]) [000]-[00]-[00]
, hit enter⏎
- Context-click the
UITextField
, find thedelegate
outlet, drag it to theMaskedTextInputListener
object - Done. Build, Run & Enjoy.
Import the library:
import InputMask
Add into the view builder:
MaskedTextField(
text: $text, // text field contents
value: $value, // extracted value
complete: $complete, // value completeness, true/false
placeholder: placeholder, // UITextField::placeholder
primaryMaskFormat: "+380 ([00]) [000]-[00]-[00]"
)
Done. Build, Run & Enjoy.