This project is a custom SwiftUI TextField
that mimics the style of Material Design.
The MaterialTextField
has the following features:
- Supports both dark mode and light mode.
- Allows a leading icon and a trailing icon.
- Provides an eye button for password fields to toggle the visibility of the password.
- Supports input hints.
- Supports input validation: If the input does not meet the requirements, the border turns pink.
- When the user enters content, the label moves to the top and becomes smaller.
First, create a MaterialTextField
and provide a name (for displaying the label) and a bound String
(for storing and updating the entered content). You can also provide a boolean value indicating whether this field should be a password field.
you can use several modifiers, for example:
MaterialTextField(name: "Password", value: $password)
.leadingIcon(Image(systemName: "lock"))
.isSecured($isSecured)
.hint("Please enter your password")
The above code will create a password field with a lock icon, and provide an eye button for showing and hiding the password, as well as a hint for the input.
You can use these modifiers freely as you need. For example, you may choose to only use the leadingIcon
modifier without the isSecured
modifier, or you may choose to only use the hint
modifier.
We welcome everyone to contribute to this project. If you find any problems or have any suggestions for improvements, please submit an issue. If you want to improve the project directly, please submit a pull request.
MIT