Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created November 15, 2017 12:23
Show Gist options
  • Save ruan65/738d62d5dd4430deb6e2128d31d497b7 to your computer and use it in GitHub Desktop.
Save ruan65/738d62d5dd4430deb6e2128d31d497b7 to your computer and use it in GitHub Desktop.
// MARK: TextViewDelegate methods for hiding keyboard by tapping anywhere and restrincting 500 chars
extension UIViewController {
@objc func textViewDidBeginEditing(_ textView: UITextView) {
}
@objc func textViewDidEndEditing(_ textView: UITextView) {
}
@objc(textView:shouldChangeTextInRange:replacementText:) func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
// goal field is varchar 500
return textView.text.count + (text.count - range.length) < 500
}
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
view.endEditing(true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment