MaterialTextFieldSwiftUI is a UI library that is built to mimic Material TextField offered by Google. It's easy to integrate and comes with some useful customizations to help in many use cases. If you like the project, please do not forget to star ★ this repository and follow me on GitHub.
- iOS 15.0+
- Xcode 11.2+
- Swift 5.0
The Example application shows how to use all the customization options available.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. Once you have your Swift package set up, adding MaterialTextFieldSwiftUI as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.package(url: "https://github.com/norrisboat/MaterialTextFieldSwiftUI.git", .branch("main"))
]
struct ContentView: View {
@State private var isPasswordValid: Bool = false
@State private var password: String = ""
@State private var isSecure: Bool = false
var body: some View {
MaterialTextField($password, placeholder: "Enter password", isValid: $isPasswordValid)
.isSecure(isSecure)
.accentColor(.purple)
.addValidations([RequiredValidator(errorMessage: "Please enter your password")])
.rightView {
Image(systemName: isPasswordShow ? "eye.fill" : "eye.slash.fill")
.foregroundColor(.gray)
.onTapGesture {
isSecure.toggle()
}
}
}
}
Extension | Description |
---|---|
.contentType(.email) | Content type of the input. It helps determine which keyboard type to show |
.accentColor(.purple) | Sets the color to show when the text field is active and the cursor color |
.addValidations([validators]) | Sets an array validations conditions |
.showError(true) | Sets the condition to show the error view |
.helperText("Some helper text") | Sets the helper text |
.isSecure(true) | Sets if input should be hidden |
.isDisabled(false) | Sets if the MaterialTextField is disabled |
.maxCharacterCount(20) | Sets the maximum character count to be accepted |
.showCharacterCounter(true) | Sets if the character counter view should show |
.leftView(AnyView()) | Sets the left view |
.rightView(AnyView()) | Sets the right view |
You can download the latest files from our Releases page. After doing so, copy the files in the Sources
folder to your project.
Feel free to fork the project and send me a pull-request!
Please file an Issue.
MaterialTextFieldSwiftUI is available under the MIT license. See the LICENSE file for more info.