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

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

$
0
0

Checking the pasteboard's string by if string == UIPasteboard.general.string takes a couple of seconds if you have long sentence in the pasteboard. The user sees the keypad is frozen while this check. My solution is to check if the length of new characters is longer than 1. If it is longer than 1, the string is from the pasteboard.

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {        if string.characters.count > 1{            //User did copy & paste        }else{            //User did input by keypad        }                     return true }

Viewing all articles
Browse latest Browse all 14

Trending Articles



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