https://github.com/dan-codes1/textfieldpicker
A SwiftUI package that provides a TextField with a Picker as its input view. The picker replaces the keyboard as the input view for the TextField.
https://github.com/dan-codes1/textfieldpicker
dependency input ios keyboard picker swift swiftpackage swiftui textfield uikit uipicker uitextfield
Last synced: 24 days ago
JSON representation
A SwiftUI package that provides a TextField with a Picker as its input view. The picker replaces the keyboard as the input view for the TextField.
- Host: GitHub
- URL: https://github.com/dan-codes1/textfieldpicker
- Owner: dan-codes1
- License: mit
- Created: 2024-10-04T10:28:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-29T23:53:35.000Z (over 1 year ago)
- Last Synced: 2025-04-05T12:14:17.222Z (about 1 year ago)
- Topics: dependency, input, ios, keyboard, picker, swift, swiftpackage, swiftui, textfield, uikit, uipicker, uitextfield
- Language: Swift
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TextFieldPicker
A SwiftUI package that provides a TextField with a Picker as its input view. The picker replaces the keyboard as the input view for the TextField.
https://github.com/user-attachments/assets/83f029db-457b-4521-9f02-79697e11d9f9
## Requirements
- iOS 13.0+
- macOS 10.13+
- Swift 5.0+
## Installation
### Swift Package Manager
To add TextFieldPicker to your Xcode project:
1. In Xcode, open your project and select **File** > **Add Packages**.
2. Paste the repository URL: https://github.com/dan-codes1/TextFieldPicker.
3. Choose the package options and add it to your target.
## Usage
Here is a simple example:
```swift
struct ContentView: View {
@State private var selectedCountry: Country? = nil
let countries = Country.allCases
var body: some View {
TextFieldPicker(selection: $selectedCountry, options: countries)
}
}
```
⚠️ **Important**: The `selection` parameter type must conform to [`Identifiable`](https://developer.apple.com/documentation/swift/identifiable) and [`CustomStringConvertible`](https://developer.apple.com/documentation/swift/customstringconvertible). The `decription` of the `CustomStringConvertible` is used as the display string for the picker options.
In this case, `country` conforms to Indetifiable and CustomStringConvertible:
```swift
enum Country: String, CaseIterable, Identifiable, CustomStringConvertible {
var id: Self { self }
case australia = "Australia"
case canada = "Canada"
case egypt = "Egypt"
case ghana = "Ghana"
case kenya = "Kenya"
case namibia = "Namibia"
case morocco = "Morocco"
case newZealand = "New Zealand"
case southAfrica = "South Africa"
case unitedKingdom = "United Kingdom"
case unitedStates = "United States"
var description: String {
self.rawValue
}
}
```
## Contribution
Contributions are welcome! Please open an issue or submit a pull request if you would like to contribute to the project.
## See Also
[TextFieldDatePicker](https://github.com/dan-codes1/TextFieldDatePicker) is a similar package but for dates. Check it out!