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.
In SWIFT 4:
func textViewDidChange(_ textView: UITextView) {
if(textView.text == UIPasteboard.general.string)
{
//Text pasted
}
}
This is what I use to detect pasted images:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (UIPasteboard.generalPasteboard.image &&
[UIPasteboard.generalPasteboard.string.lowercaseString isEqualToString:text.lowercaseString]) {
//Pasted image
return NO;
}
return YES;
}
This working Perfect Xcode 9.4 Swift 4.1
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text.contains(UIPasteboard.general.string ?? "") {
return false
}
return true
}
When ever the user try to Paste into text field the if condition will execute
This code will stop pasting