Skip to content

Commit 89f9c2e

Browse files
committed
Updated ReadMe file.
1 parent fea9d3a commit 89f9c2e

File tree

1 file changed

+19
-38
lines changed

1 file changed

+19
-38
lines changed

README.md

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ Text formatting framework written on Swift 4.0.
1717
:performing_arts:| Convert string into formatted string and vice versa
1818
:bicyclist:| Formatting text during typing
1919
:hash:| Set format using '#' characters like '### ##-###'
20-
:paperclip:| Set prefix for editing string
21-
:see_no_evil:| Symbols input control with RegEx
22-
:globe_with_meridians:| Works with textField/textView/etc with common interface
23-
:gift:| Ready to use subclasses of UITextField and UITextView
24-
:mag:| Allows easy to set attributes for string in range
20+
2521

2622
## Example
2723

@@ -44,6 +40,7 @@ To run the example project, clone the repo and run `pod install` from the Exampl
4440
## Migration Guides
4541

4642
- [AnyFormatKit 0.2.0 MigrationGuide](https://github.com/luximetr/AnyFormatKit/blob/master/Documentation/AnyFormatKit%200.2.0%20MigrationGuide.md)
43+
- [AnyFormatKit 1.0.0 MigrationGuide](https://github.com/luximetr/AnyFormatKit/blob/master/Documentation/AnyFormatKit%201.0.0%20MigrationGuide.md)
4744

4845
## Installation
4946

@@ -83,61 +80,45 @@ import AnyFormatKit
8380
### Formatting with TextFormatter
8481

8582
```swift
86-
let phoneFormatter = TextFormatter(textPattern: "### (###) ###-##-##")
87-
phoneFormatter.formattedText(from: "+123456789012") // +12 (345) 678-90-12
83+
let phoneFormatter = DefaultTextFormatter(textPattern: "### (###) ###-##-##")
84+
phoneFormatter.format("+123456789012") // +12 (345) 678-90-12
8885

89-
let customFormatter = TextFormatter(textPattern: "###-###custom###-###")
90-
customFormatter.formattedText(from: "111222333444") // 111-222custom333-444
86+
let customFormatter = DefaultTextFormatter(textPattern: "###-###custom###-###")
87+
customFormatter.format("111222333444") // 111-222custom333-444
9188
```
9289

9390
You can also set your own symbol in the pattern
9491

9592
```swift
96-
let cardFormatter = TextFormatter(textPattern: "XXXX XXXX XXXX XXXX", patternSymbol: "X")
97-
cardFormatter.formattedText(from: "4444555566667777") // 4444 5555 6666 7777
93+
let cardFormatter = DefaultTextFormatter(textPattern: "XXXX XXXX XXXX XXXX", patternSymbol: "X")
94+
cardFormatter.format("4444555566667777") // 4444 5555 6666 7777
9895
```
9996

10097
For string with different length
10198

10299
```swift
103-
let formatter = TextFormatter(textPattern: "## ###-##")
104-
formatter.formattedText(from: "1234") // 12 34
105-
formatter.formattedText(from: "123456789") // 12 345-67
100+
let formatter = DefaultTextFormatter(textPattern: "## ###-##")
101+
formatter.format("1234") // 12 34
102+
formatter.format("123456789") // 12 345-67
106103
```
107104

108105
Unformatting
109106

110107
```swift
111-
let formatter = TextFormatter(textPattern: "## ###-##")
112-
formatter.unformattedText(from: "99 888-77") // 9988877
108+
let formatter = DefaultTextFormatter(textPattern: "## ###-##")
109+
formatter.unformat("99 888-77") // 9988877
113110
```
114111
### Formatting during typing
115112

116-
It is necessary to create TextInputController instance with formatter for formatting during typing. You need to implement `TextInput` protocol in your own `UITextField`/`UITextView`/something else or use ready solutions (`TextInputField`/`TextInputView`) by subclassing. It is necessary to set controllers's `textInput` property.
117-
118-
```swift
119-
let textInputController = TextInputController()
120-
121-
let textInput = TextInputField() // or TextInputView or any TextInput
122-
textInputController.textInput = textInput // setting textInput
123-
124-
let formatter = TextInputFormatter(textPattern: "### (###) ###-##-##", prefix: "+12")
125-
textInputController.formatter = formatter // setting formatter
126-
```
127-
The controller listens `textInput(_:shouldChangeCharactersIn:replacementString:)` delegate method. But you can also add more than one delegate if needed. Methods of the delegates, that should return `Bool` value gather using `&&` operator. Therefore, if one of the delegates returns `false`, that means that `textInput` will receive `false`. If you want to send `true` to `textInput`, all delegates must return `true`.
128-
129-
You can set `allowedSymbolsRegex` to the formatter to filter input symbols with the RegEx. All symbols, that satisfy the RegEx will be available for typing in the `textInput`.
130-
This property only applies to inputed symbols from the keyboard, but not to the prefix.
113+
Code from example app
131114

132115
```swift
133-
inputFieldFormatter.allowedSymbolsRegex = "[0-9]" // allowed only numbers
134-
```
116+
let formatter = DefaultTextInputFormatter(textPattern: "### (###) ###-##-##")
135117

136-
### Attributes for range
137-
138-
To set attributes for string at range use `addAttributes(_:range:)` method for `textInput`.
139-
```swift
140-
textInput.addAttributes([.foregroundColor : UIColor.lightGray], range: NSRange(location: 0, length: 3))
118+
// inside of UITextFieldDelegate shouldChangeTextIn method
119+
let result = formatter.formatInput(currentText: textView.text, range: range, replacementString: text)
120+
textView.text = result.formattedText
121+
textView.setCursorLocation(result.caretBeginOffset)
141122
```
142123

143124
## Author

0 commit comments

Comments
 (0)