A simple TextField with a maximum lenght, for SwiftUI.
Installing LimitedTextField is a really straight-forward process. All you need to do is:
-
Go to
File -> Swift Packages -> Add Package Dependency. -
Paste this project's url
https://github.com/iAlex11/LimitedTextField. -
Enjoy!
Implementing LimitedTextField in your project is as simple as adding 1 line of code (yes, just one line of code) to your SwiftUI view.
LimitedTextField()You can easily adjust the maximum length allowed thanks to the .count() function.
LimitedTextField()
.count(/* The max length */)There might be ocassions where you may want to have a limit for the amount of words, and not be conditioned by the amount of characters. You can achieve this easily by using .byWord().
LimitedTextField()
.counter(.byWord(5))LimitedTextField is just a simple TextField without styling, so you can style it easily.
LimitedTextField()
.padding()
.background(
Color(.systemGray5)
.cornerRadius(5.0)
)In the nature of open-source, any pull-request is welcome. Simply open a pull-request and I'll be happy to merge it.
Distributed under the GPLv3 license. See LICENSE for more information.
Coded with ❤️ by Alejandro Modroño 🇪🇸 – hello@amodrono.com
