KoTextCountLimit is a library designed to address issues that arise when applying character limits to UITextView and UITextField with Korean input. It ensures that character limits are enforced correctly, even with the unique characteristics of the Korean language.
- Resolves issues where the final character's consonant, vowel, or backspace is not properly registered when enforcing character limits in Korean input.
- Swift 5.10
- iOS 13+
- In Xcode, select File > Swift Packages > Add Package Dependency.
- Enter the project's GitHub URL: https://github.com/iOS-Ruel/KoTextCountLimit.git.
- Choose the version or branch you want to install, then click Next.
- Click Finish to complete the installation.
- Clone or download this repository.
- Drag and drop the KoTextCountLimit folder into your project in Xcode.
- Select Copy items if needed and click Finish.
- Usage with UITextView
- You can use it like this with UITextView. The same approach applies to UITextField.
- Create an instance of
KoTextCountLimit()
. - Call the
shouldChangeText(for:in:replacementText:maxCharacterLimit) method
.
class ViewController: UIViewController {
let textLimit = KoTextCountLimit()
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView,
shouldChangeTextIn range: NSRange,
replacementText text: String) -> Bool {
return textLimit.shouldChangeText(for: textView,
in: range,
replacementText: text,
maxCharacterLimit: 10)
}
}
/*
func shouldChangeText(for textInput: UITextInput,
in range: NSRange,
replacementText text: String,
maxCharacterLimit: Int) -> Bool
*/
- Fork this repository.
- Create a new feature branch (
git checkout -b feat/featName
). - Commit your changes (
git commit -m 'Add some featName'
). - Push to the branch (
git push origin feat/featName
). - Open a Pull Request.
- Contributions are always welcome to this open-source project 🤗
This project is licensed under the MIT License. See the LICENSE file for more details.