Skip to content

MaterialTextFieldSwiftUI is a UI library that is built to mimic Material TextField offered by Google

License

Notifications You must be signed in to change notification settings

norrisboat/MaterialTextFieldSwiftUI

Repository files navigation

MaterialTextFieldSwiftUI

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.

Platforms iOS twitter SPM MIT

📦 Requirements

  • iOS 15.0+
  • Xcode 11.2+
  • Swift 5.0

📸 Demo

The Example application shows how to use all the customization options available.

Demo

💾 Installation

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"))
]

💻 Usages

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()
                    }
            }
    }
}

Password Demo

⚙️ Customizations

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

📘 Manual

You can download the latest files from our Releases page. After doing so, copy the files in the Sources folder to your project.

🙋🏻‍♂️ Author

twitter

💰 Contribution

Feel free to fork the project and send me a pull-request!

📝 Feedback

Please file an Issue.

📜 License

MaterialTextFieldSwiftUI is available under the MIT license. See the LICENSE file for more info.

About

MaterialTextFieldSwiftUI is a UI library that is built to mimic Material TextField offered by Google

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages