Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qiwi/formattabletextview
Allows you to format user input according to your mask
https://github.com/qiwi/formattabletextview
ui
Last synced: 4 days ago
JSON representation
Allows you to format user input according to your mask
- Host: GitHub
- URL: https://github.com/qiwi/formattabletextview
- Owner: qiwi
- License: mit
- Created: 2019-03-05T08:21:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-01T13:55:55.000Z (almost 3 years ago)
- Last Synced: 2024-07-16T14:21:14.316Z (4 months ago)
- Topics: ui
- Language: Swift
- Homepage:
- Size: 701 KB
- Stars: 28
- Watchers: 10
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FormattableTextView
## Description
FormattableTextView is a framework which allows you to format user input according to your mask. There are 2 implementations: for UITextView and for UITextField. UITextField is less memory consuming, UITextView is more flexible for customization. You can choose either one.When you select the text in this field, only your input text is selected because non-input symbols are drawn in other layers.
This approach allows to:
* prohibit user from putting the cursor in non-input symbols ranges
* avoid problems when adding/removing symbols inside existing text
* customize input and non-input attributes separately.## Requirements
* iOS 8.0+## Installation
### CocoaPods
```
pod 'FormattableTextView', :git => 'https://github.com/qiwi/FormattableTextView'
```### Carthage
```
git "https://github.com/qiwi/FormattableTextView" "master"
```## Usage
### Example
```swift
let field = FormattableTextField()
field.formatSymbols = ["d": CharacterSet.decimalDigits,
"w": CharacterSet.lowercaseLetters]
field.format = "dd.dd.dddd"
field.maskAppearance = .leftOnly
field.inputAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)]
field.maskAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
NSAttributedString.Key.foregroundColor: UIColor.lightGray]```
### Usage notes
Set the mask with `format` property. By default `d` means digits, `w` means letters and `*` means any symbol.
Examples:
* `+7(ddd)ddd-dd-dd` - phone number format for Russia
* `dd.dd.dddd` - date format
* `www*d dd` - 3 letters, any symbol, digit and 2 other digits after non-input spaceYou can set your own custom mapping using `formatSymbols` property. All other symbols will be considered as non-input.
Non-input symbols have 3 appearance options:
* `leftOnly`
You will see only those non-input symbols which are located to the left of your inputted symbols* `leftAndRight`
You will see only those non-input symbols which are located to the left and to the right of your inputted symbols* `whole`
You will see all non-input symbols and placeholders for input symbols. Every key in `placeholders` parameter must exist among the `formatSymbols` keys. In this mode `inputAttributes` and `maskAttributes` properties have to be the same. Your font must be monospaced.If you need to set input text programmatically use `text` property.
For left inset use `insetX` property.
You can modify input and non-input symbols appearance by using `inputAttributes` and `maskAttributes` properties.
## License
Distributed under the MIT License.