RXswift Setting maximum number of characters of UITextView
Problem:
I want to set maximum number of characters for UITextview.How do i achieve that using rxswift?
Solution:
// MARK: - Limit textview charecters
func limitTextViewCharacters(tv:UIT
if let tView = tv {
guard tView.text.count > limit else {
return
}
let index = tView.text.index(tView.text.st
tView.text = String(tView.text.prefix(upTo: index))
}
}
Add the above function in utils.
Then in your viewcontroller add the below code in viewdidload
TxtView.rx.text.changed
.subscribe(onNext: {_ in
limitTextViewCharacters(tv: self.TxtView, limit: TextLimit)
let name = self.TxtView.text
}).disposed(by: self.disposeBag)
Comments
Post a Comment