ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - RedMadRobot/input-mask-ios: User input masking library repo.
User input masking library repo. Contribute to RedMadRobot/input-mask-ios development by creating an account on GitHub.
Visit Site

GitHub - RedMadRobot/input-mask-ios: User input masking library repo.

GitHub - RedMadRobot/input-mask-ios: User input masking library repo.

Pod Version Badge Awesome Actions Android Telegram license

Input masks restrict data input and allow you to guide users to enter correct values.
Check out our wiki for quick start and further reading.

⚙️ Features

  • Apply formatting to your text fields, see examples
  • Filter out nonessential symbols (e.g. extract 0123456 from +1 (999) 012-34-56)
  • For international phone numbers
    • guess the country from the entered digits
    • apply corresponding value restrictions (e.g. a 🇺🇸US phone will have a format like +1 201 456-7890)
  • Apply number/currency formatting
  • SwiftUI support
  • macOS support

💳 Examples

  • Phone numbers: +1 ([000]) [000] [00] [00]
  • Dates: [00]{.}[00]{.}[9900]
  • Serial numbers: [AA]-[00000099]
  • IPv4: [099]{.}[099]{.}[099]{.}[099]
  • Visa/MasterCard numbers: [0000] [0000] [0000] [0000]
  • UK IBAN: GB[00] [____] [0000] [0000] [0000] [00]

🛠️ Installation

Swift Package Manager

dependencies: [
    .Package(url: "https://github.com/RedMadRobot/input-mask-ios", majorVersion: 7)
]

CocoaPods

pod 'InputMask'

Manual

  1. git clone this repository;
  2. Add InputMask.xcodeproj into your project/workspace;
  3. Go to your target's settings, add InputMask.framework under the Embedded Binaries section
  4. For ObjC projects:
    • (~Xcode 8.x) make sure Build Options has Embedded Content Contains Swift Code enabled;
    • import bridging header.

📢 Communication, Questions & Issues

Please take a closer look at our Known issues section before you incorporate our library into your project.

For your bugreports and feature requests please file new issues via GitHub.

Should you have any questions, please search for closed issues or ask questions at StackOverflow with the input-mask tag.

❗Known issues

UITextFieldTextDidChange notification and target-action editingChanged event

UITextField with assigned MaskedTextFieldDelegate object won't issue UITextFieldTextDidChange notifications and editingChanged control events. This happens due to the textField(_:shouldChangeCharactersIn:replacementString:) method implementation, which always returns false.

Consider using following workaround in case if you do really need to catch editing events:

class NotifyingMaskedTextFieldDelegate: MaskedTextFieldDelegate {
    weak var editingListener: NotifyingMaskedTextFieldDelegateListener?
    
    override func textField(
        _ textField: UITextField,
        shouldChangeCharactersIn range: NSRange,
        replacementString string: String
    ) -> Bool {
        defer {
            self.editingListener?.onEditingChanged(inTextField: textField)
        }
        return super.textField(textField, shouldChangeCharactersIn: range, replacementString: string)
    }
}


protocol NotifyingMaskedTextFieldDelegateListener: class {
    func onEditingChanged(inTextField: UITextField)
}

Please, avoid at all costs sending SDK events and notifications manually.

Carthage vs. IBDesignables, IBInspectables, views and their outlets

Interface Builder struggles to support modules imported in a form of a dynamic framework. For instance, custom views annotated as IBDesignable, containing IBInspectable and IBOutlet fields aren't recognized properly from the drag'n'dropped *.framework.

In case you are using our library as a Carthage-built dynamic framework, be aware you won't be able to easily wire your MaskedTextFieldDelegate objects and their listeners from storyboards in your project. There is a couple of workarounds described in the corresponding discussion, though.

Also, consider filing a radar to Apple, like this one.

Cut action doesn't put text into the pasteboard

When you cut text, characters get deleted yet you won't be able to paste them somewhere as they aren't actually in your pasteboard.

iOS hardwires UIMenuController's cut action to the UITextFieldDelegate's textField(_:shouldChangeCharactersIn:replacementString:) return value. This means "Cut" behaviour actually depends on the ability to edit the text.

Bad news are, our library returns false in textField(_:shouldChangeCharactersIn:replacementString:), and heavily depends on this false. It would require us to rewrite a lot of logic in order to change this design, and there's no guarantee we'll be able to do so.

Essentially, there's no distinct way to differentiate "Cut selection" and "Delete selection" actions on the UITextFieldDelegate side. However, you may consider using a workaround, which will require you to subclass UITextField overriding its cut(sender:) method like this:

class UITextFieldMonkeyPatch: UITextField {
    override func cut(_ sender: Any?) {
        copy(sender)
        super.cut(sender)
    }
}

From our library perspective, this looks like a highly invasive solution. Thus, in the long term, we are going to investigate a "costly" method to bring the behaviour matching the iOS SDK logic. Yet, here "long term" might mean months.

Incorrect cursor position after pasting

Shortly after new text is being pasted from the clipboard, every UITextInput receives a new value for its selectedTextRange property from the system. This new range is not consistent with the formatted text and calculated caret position most of the time, yet it's being assigned just after set caretPosition call.

To ensure correct caret position is set, it might be assigned asynchronously (presumably after a vanishingly small delay), if caret movement is set to be non-atomic; see MaskedTextFieldDelegate.atomicCursorMovement property.

MaskedTextInputListener

In case you are wondering why do we have two separate UITextFieldDelegate and UITextViewDelegate implementations, the answer is simple: prior to iOS 11 UITextField and UITextView had different behaviour in some key situations, which made it difficult to implement common logic.

Both had the same bug with the UITextInput.beginningOfDocument property, which rendered impossible to use the generic UITextInput protocol UITextField and UITextView have in common.

Since iOS 11 most of the things received their fixes (except for the UITextView edge case). In case your project is not going to support anything below 11, consider using the modern MaskedTextInputListener.

🙏 Special thanks

These folks rock:

♻️ License

The library is distributed under the MIT LICENSE.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory