Quantcast
Channel: How to know when text is pasted into a UITextView? - Stack Overflow
Viewing all articles
Browse latest Browse all 14

Answer by danielrosero for How to know when text is pasted into a UITextView?

$
0
0

carlos16196 was a good approach, but I would also tweak it by changing [text isEqualToString:[UIPasteboard generalPasteboard].string] to [text containsString:[UIPasteboard generalPasteboard].string]

By doing this, you will detect when user pastes in the textview after other typed text that is not in the UIPasteboard.

This is the code:

-(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 boardif ([text containsString:[UIPasteboard generalPasteboard].string]) {    // code to execute in case user is using paste} else {    // code to execute other wise}return YES;}

Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>