https://github.com/aaronmade/respondabletextfield
Respondable TextField for SwiftUI
https://github.com/aaronmade/respondabletextfield
ios responder swift swiftpm swiftui textfield
Last synced: 10 months ago
JSON representation
Respondable TextField for SwiftUI
- Host: GitHub
- URL: https://github.com/aaronmade/respondabletextfield
- Owner: aaronmade
- License: mit
- Created: 2020-12-17T12:34:23.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-24T10:13:37.000Z (about 5 years ago)
- Last Synced: 2025-08-17T12:37:10.688Z (10 months ago)
- Topics: ios, responder, swift, swiftpm, swiftui, textfield
- Language: Swift
- Homepage: https://github.com/aaronLab/RespondableTextField
- Size: 125 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://developer.apple.com/swift)


[](https://github.com/aaronLab/SweetCardScanner/blob/main/LICENSE)
[](https://github.com/aaronLab/RespondableTextField/releases/tag/v1.0.2)
# RespondableTextField
`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.

## Requirements
- iOS 13.0+ (due to SwiftUI)
## Installation
- In Xcode, add the URL of this repository in SwiftPM:
```http
https://github.com/aaronLab/RespondableTextField.git
```
## Usage
- `import RespondableTextField`
- Add `RespondableTextField` in your body like below.
- **_⚠️ To make it work properly: The tags of each RespondableTextField in each body must be increased SEQUENTIALLY in order. ⚠️_**
```Swift
RespondableTextField(
text: Binding,
tag: Int,
isFirstResponder: Bool = false,
placeholder: String? = nil,
width: CGFloat? = nil,
height: CGFloat? = nil,
onEditing: ((String) -> Void)? = nil,
didBeginEditing: (() -> Void)? = nil,
didEndEditing: (() -> Void)? = nil,
shouldReturn: ((String?) -> Void)? = nil
)
```
- Also, you don't have to fill all of the optional parameters or `isFirstResponder`.
- You can make the textField the first responder with `isFirstResponder = true`.
## Extensions
- `respondableSecureType()`
- Secure type
- `respondableKeyboardType(_ type: UIKeyboardType)`
- Change keyboard type
- `respondableContentType(_ type: UITextContentType)`
- Change content type
- `respondableCapitalization(_ type: UITextAutocapitalizationType)`
- Capitalization change
- `respondableFont(_ font: UIFont)`
- Change font
- `respondableLineStyle()`
- Borderstyle: .line
- `respondableBezelStyle()`
- Borderstyle: .bezel
- `textFieldStyle(_ style: S) -> some View where S: TextFieldStyle`
- Borderstyle: .roundedRect, .none
## Example
You can use or customize RespondableTextField like below, or [see example file](./Example/Example/ContentView.swift).
```Swift
//
// ContentView.swift
// Example
//
// Created by Aaron Lee on 2020-12-17.
//
import SwiftUI
import RespondableTextField
struct ContentView: View {
// MARK: - PROPERTIES
@State private var text1: String = ""
@State private var text2: String = ""
@State private var text3: String = ""
@State private var text4: String = ""
// MARK: - BODY
var body: some View {
ScrollView(showsIndicators: false) {
VStack(alignment: .leading, spacing: 30) {
// Default
Group {
Text("Default")
.font(.system(size: 14, weight: .bold, design: .default))
RespondableTextField(text: $text1,
tag: 0,
isFirstResponder: true,
placeholder: "1st") { value in
print("onEditing: \(value)")
} didBeginEditing: {
print("didBeginEditing")
} didEndEditing: {
print("didEndEditing")
} shouldReturn: { value in
print("shouldReturn: \(value ?? "N/A")")
}
Text(text1)
}
// SecureType + RectangleLine Border
Group {
Text("SecureType + RectangleLine Border")
.font(.system(size: 14, weight: .bold, design: .default))
RespondableTextField(text: $text2,
tag: 1,
placeholder: "2nd",
width: 200,
height: 50) { value in
print("onEditing: \(value)")
} didBeginEditing: {
print("didBeginEditing")
} didEndEditing: {
print("didEndEditing")
} shouldReturn: { value in
print("shouldReturn: \(value ?? "N/A")")
}
.respondableSecureType()
.respondableLineStyle()
Text(text2)
}
// NumberPad + OneTimeCode + Rounded Border
Group {
Text("NumberPad + OneTimeCode + Rounded Border")
.font(.system(size: 14, weight: .bold, design: .default))
RespondableTextField(text: $text3,
tag: 2,
placeholder: "3rd") { value in
print("onEditing: \(value)")
} didBeginEditing: {
print("didBeginEditing")
} didEndEditing: {
print("didEndEditing")
} shouldReturn: { value in
print("shouldReturn: \(value ?? "N/A")")
}
.respondableKeyboardType(.numberPad)
.respondableContentType(.oneTimeCode)
.textFieldStyle(RoundedBorderTextFieldStyle())
Text(text3)
}
// didEndEditing + Bazel Border + Font
Group {
Text("didBeginEditing + didEndEditing + Bazel Border")
.font(.system(size: 14, weight: .bold, design: .default))
RespondableTextField(text: $text4,
tag: 3,
placeholder: "4th") { value in
print("onEditing: \(value)")
} didBeginEditing: {
print("didBeginEditing")
} didEndEditing: {
print("didEndEditing")
} shouldReturn: { value in
print("shouldReturn: \(value ?? "N/A")")
}
.respondableBezelStyle()
.respondableFont(.systemFont(ofSize: 20, weight: .bold))
Text(text4)
}
} //: V
.padding()
} //: S
.preferredColorScheme(.light)
}
}
```
## License
Licensed under [MIT](./LICENSE)