Created
November 15, 2017 12:23
-
-
Save ruan65/738d62d5dd4430deb6e2128d31d497b7 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
// 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