how to know when text is pasted into UITextView

后端 未结 9 473
暗喜
暗喜 2020-11-30 10:15

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.

Thanks for reading.

9条回答
  •  既然无缘
    2020-11-30 10:23

    Here is what i use to detect paste events in UITextView:

     // Set this class to be the delegate of the UITextView. Now when a user will paste a text in that textview, this delegate will be called.
    -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
        // Here we check if the replacement text is equal to the string we are currently holding in the paste board
        if ([text isEqualToString:[UIPasteboard generalPasteboard].string]) {
    
            // code to execute in case user is using paste
    
        } else {
    
            // code to execute other wise
        }
    
        return YES;
    }
    

提交回复
热议问题