Skip to content

Instantly share code, notes, and snippets.

@Abhishek9634
Created July 20, 2020 18:48
Show Gist options
  • Save Abhishek9634/6093cea8da1da45ce0b79b2aaf0b04ab to your computer and use it in GitHub Desktop.
Save Abhishek9634/6093cea8da1da45ce0b79b2aaf0b04ab to your computer and use it in GitHub Desktop.
extension ViewController: UITextViewDelegate {
private func setupTextView() {
self.commentTextView.delegate = self
}
func textViewDidEndEditing(_ textView: UITextView) {
self.placeHolderLabel.isHidden = !textView.text.isEmpty
}
func textViewDidChange(_ textView: UITextView) {
var height = self.minHeight
if textView.contentSize.height <= self.minHeight {
height = self.minHeight
} else if textView.contentSize.height >= self.maxHeight {
height = self.maxHeight
} else {
height = textView.contentSize.height
}
self.placeHolderLabel.isHidden = !textView.text.isEmpty
self.commentConstraint.constant = height
UIView.animate(withDuration: 0.1) {
self.view.layoutIfNeeded()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment