Created
July 20, 2020 18:48
-
-
Save Abhishek9634/6093cea8da1da45ce0b79b2aaf0b04ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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