Swift Code
Implement UITextViewDelegate in your class / View like so:
class MyClass: UITextViewDelegate { ... set the textView delegate to self
myTextView.delegate = self And then implement the following:
func textViewDidChange(_ textView: UITextView) { if countElements(textView.text).characters.count >= 1 { if let lastChar = textView.text.substringFromIndex(advance(textView.textcharacters.endIndex,last -1)){ if(lastChar == "\n"){ textView.text = textView.text.substringToIndexsubstring(advanceto: textView.text.index(before: textView.text.endIndex, -1)) textView.resignFirstResponder() } } } } EDIT I updated the code because it is never a good idea to change the user input in a textfield to for a workarround and not resetting the state after the hack code completed.