Skip to content

Commit e047661

Browse files
committed
chore: Update README.md
1 parent 533a307 commit e047661

1 file changed

Lines changed: 141 additions & 1 deletion

File tree

README.md

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,143 @@
1+
[![Language: Swift 5](https://img.shields.io/badge/language-Swift5-orange?style=flat&logo=swift)](https://developer.apple.com/swift)
2+
![Platform: iOS 13+](https://img.shields.io/badge/platform-iOS%2013%2B-blue?style=flat&logo=apple)
3+
![SwiftPM compatible](https://img.shields.io/badge/SPM-compatible-brightgreen?style=flat&logo=swift)
4+
[![License: MIT](https://img.shields.io/badge/license-MIT-lightgrey?style=flat)](https://github.com/aaronLab/SweetCardScanner/blob/main/LICENSE)
5+
16
# RespondableTextField
27

3-
Respondable TextField for SwiftUI
8+
`RespondableTextField` is a simple textField library for SwiftUI. The reason why I wanted to make this library was because I was too lazy to make `UIViewRepresentable`views every single time. Also, I know you were really struggling from, or tired of taking care of UITextFieldDelegate methods, such as `becomeFirstResponder`, `resignFirstResponder`. I really hope this helps you.s
9+
10+
<img src="./preview.png" width="260">
11+
12+
## Requirements
13+
14+
- iOS 13.0+ (due to SwiftUI)
15+
16+
## Installation
17+
18+
- In Xcode, add the URL of this repository in SwiftPM:
19+
20+
```http
21+
https://github.com/aaronLab/RespondableTextField
22+
```
23+
24+
## Usage
25+
26+
- `import RespondableTextField`
27+
- Add `RespondableTextField` in your body like below.
28+
- **_⚠️To make it work properly: The tags of each RespondableTextField in each body must be increased SEQUENTIALLY in order.⚠️_**
29+
30+
```Swift
31+
RespondableTextField(
32+
tag: Int,
33+
placeholder: String?,
34+
onEditing: ((String) -> Void)?,
35+
onCommitted: (() -> Void)?,
36+
didBeginEditing: (() -> Void)?,
37+
didEndEditing: ((UITextField.DidEndEditingReason) -> Void)?
38+
)
39+
```
40+
41+
- Also, you don't have to fill all of the optional parameters.
42+
43+
## Example
44+
45+
You can use or customize RespondableTextField like below, or [see example file](./Example/Example/ContentView.swift).
46+
47+
```Swift
48+
//
49+
// ContentView.swift
50+
// Example
51+
//
52+
// Created by Aaron Lee on 2020-12-17.
53+
//
54+
55+
import SwiftUI
56+
import RespondableTextField
57+
58+
struct ContentView: View {
59+
// MARK: - PROPERTIES
60+
61+
@State private var text1: String = ""
62+
@State private var text2: String = ""
63+
@State private var text3: String = ""
64+
@State private var text4: String = ""
65+
66+
// MARK: - BODY
67+
68+
var body: some View {
69+
VStack(alignment: .leading, spacing: 30) {
70+
71+
// Default
72+
Group {
73+
Text("Default")
74+
.font(.system(size: 14, weight: .bold, design: .default))
75+
RespondableTextField(tag: 0, placeholder: "First TextField") { value in
76+
self.text1 = value
77+
} onCommitted: {
78+
print(self.text1)
79+
}
80+
Text(text1)
81+
}
82+
83+
// SecureType + RectangleLine Border
84+
Group {
85+
Text("SecureType + RectangleLine Border")
86+
.font(.system(size: 14, weight: .bold, design: .default))
87+
RespondableTextField(tag: 1, placeholder: "Second TextField") { value in
88+
self.text2 = value
89+
}
90+
.respondableSecureType()
91+
.respondableLineStyle()
92+
93+
Text(text2)
94+
}
95+
96+
// NumberPad + OneTimeCode + Rounded Border
97+
Group {
98+
Text("NumberPad + OneTimeCode + Rounded Border")
99+
.font(.system(size: 14, weight: .bold, design: .default))
100+
RespondableTextField(tag: 2, placeholder: "Third TextField") { value in
101+
self.text3 = value
102+
} onCommitted: {
103+
print(self.text3)
104+
}
105+
.respondableKeyboardType(.numberPad)
106+
.respondableContentType(.oneTimeCode)
107+
.textFieldStyle(RoundedBorderTextFieldStyle())
108+
109+
Text(text3)
110+
}
111+
112+
// didBeginEditing + didEndEditing + Bazel Border + Font
113+
Group {
114+
Text("didBeginEditing + didEndEditing + Bazel Border")
115+
.font(.system(size: 14, weight: .bold, design: .default))
116+
RespondableTextField(tag: 3, placeholder: "Fourth TextField") { value in
117+
self.text4 = value
118+
} didBeginEditing: {
119+
print("Begin")
120+
} didEndEditing: { _ in
121+
print("Done")
122+
}
123+
.respondableBezelStyle()
124+
.respondableFont(.systemFont(ofSize: 20, weight: .bold))
125+
}
126+
127+
} //: V
128+
.padding()
129+
130+
}
131+
}
132+
133+
struct ContentView_Previews: PreviewProvider {
134+
static var previews: some View {
135+
ContentView()
136+
}
137+
}
138+
139+
```
140+
141+
## License
142+
143+
Licensed under [MIT](./LICENSE)

0 commit comments

Comments
 (0)