Get Updates By E-mail 

return

Custom Behavior On Return For A UITextView

  •  
  •  
  •  
  •  
  •  

The default behavior for a UITextField on pressing the return key is to execute the textFieldShouldReturn: method of the UITextFieldDelegate.

What if we wanted to create similar behavior with a a UITextView which does not have an equivalent method and by default just creates a new line?

Nick Dalton has come up with a snippet of code that uses the:

textView:shouldChangeTextInRange:replacementText:

method of the UITextViewDelegate to do just that.

You can check the article out here: Handling The Return Key In A UITextView

It’s a very handy bit of code to have as there are many situations where you may want to implement custom behavior when the return key is pressed in a UITextView.

Thanks Nick.

Please post any comments below, thanks.


  •  
  •  
  •  
  •  
  •