iosuikituitextview

How to know when text is pasted into a UITextView?


What event is fired when a block of text is pasted into a UITextView? I need to modify the frame of my textView when the text is pasted in.


Solution

  • Your UITextView will call its UITextViewDelegate method

     - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    

    if a delegate has been set up. This gets called both when a character is typed on the keyboard, and when text is pasted into the text view. The text pasted in is the replacementText argument.

    See http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html#//apple_ref/occ/intf/UITextViewDelegate