forked from luximetr/AnyFormatKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated version to '2.1.0', modified readme file.
- Loading branch information
Oleksandr Orlov
committed
Jan 16, 2021
1 parent
a8973d5
commit 47d7982
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
[](https://travis-ci.org/luximetr/AnyFormatKit) | ||
[](http://cocoapods.org/pods/AnyFormatKit) | ||
[](https://github.com/Carthage/Carthage) | ||
[](http://cocoapods.org/pods/AnyFormatKit) | ||
[](http://cocoapods.org/pods/AnyFormatKit) | ||
 | ||
|
@@ -17,6 +16,9 @@ Text formatting framework written on Swift 5.0. | |
:performing_arts:| Convert string into formatted string and vice versa | ||
:bicyclist:| Formatting text during typing | ||
:hash:| Set format using '#' characters like '### ##-###' | ||
:stuck_out_tongue:| Supporting emojis | ||
:heavy_dollar_sign:| Formatting money amount | ||
:parking:| Formatting with placeholders | ||
|
||
|
||
## Example | ||
|
@@ -59,6 +61,16 @@ Then, run the following command: | |
$ pod install | ||
``` | ||
|
||
### Swift Package Manager | ||
AnyFormatKit is available with [Swift Package Manager](https://swift.org/package-manager/). | ||
Once you have your Swift package set up, than simply add AnyFormatKit to the `dependencies` value of your `Package.swift` | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/luximetr/AnyFormatKit.git", .upToNextMajor(from: "2.1.0")) | ||
] | ||
``` | ||
|
||
## Usage | ||
|
||
### Import | ||
|
@@ -98,9 +110,23 @@ Unformatting | |
let formatter = DefaultTextFormatter(textPattern: "## ###-##") | ||
formatter.unformat("99 888-77") // 9988877 | ||
``` | ||
### Formatting with PlaceholderTextFormatter | ||
|
||
```swift | ||
let phoneFormatter = PlaceholderTextFormatter(textPattern: "### (###) ###-##-##") | ||
phoneFormatter.format("+123") // +12 (3##) ###-##-## | ||
``` | ||
|
||
### Formatting with SumTextFormatter | ||
|
||
```swift | ||
let formatter = SumTextFormatter(textPattern: "#,###.##") | ||
formatter.format("1234.13") // 1,234.13 | ||
``` | ||
|
||
### Formatting during typing | ||
|
||
Code from example app | ||
Using `DefaultTextInputFormatter` formatter | ||
|
||
```swift | ||
let formatter = DefaultTextInputFormatter(textPattern: "### (###) ###-##-##") | ||
|
@@ -111,6 +137,28 @@ textView.text = result.formattedText | |
textView.setCursorLocation(result.caretBeginOffset) | ||
``` | ||
|
||
Using `SumTextInputFormatter` formatter | ||
|
||
```swift | ||
let formatter = SumTextInputFormatter(textPattern: "#,###.##$") | ||
|
||
// inside of UITextFieldDelegate shouldChangeTextIn method | ||
let result = formatter.formatInput(currentText: textView.text, range: range, replacementString: text) | ||
textView.text = result.formattedText | ||
textView.setCursorLocation(result.caretBeginOffset) | ||
``` | ||
|
||
Using `PlaceholderTextInputFormatter` formatter | ||
|
||
```swift | ||
let formatter = PlaceholderTextInputFormatter(textPattern: "#### #### #### ####") | ||
|
||
// inside of UITextFieldDelegate shouldChangeTextIn method | ||
let result = formatter.formatInput(currentText: textView.text, range: range, replacementString: text) | ||
textView.text = result.formattedText | ||
textView.setCursorLocation(result.caretBeginOffset) | ||
``` | ||
|
||
## Author | ||
|
||
luximetr, [email protected] | ||
|