I need to support pasting of images into a UITextView
. With an image copied to the clipboard, the "Paste
" option doesn't seem to pop up. It does when there's text on the clipboard.
This is how to override the paste
option in a custom UITextView
. But I need help on how to get the option to show up to begin with...
// This gets called when user presses menu "Paste" option
- (void)paste:(id)sender{
UIImage *image = [UIPasteboard generalPasteboard].image;
if (image) {
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = image;
NSAttributedString *imageString = [NSAttributedString attributedStringWithAttachment:textAttachment];
self.attributedText = imageString;
} else {
// Call the normal paste action
[super paste:sender];
}
}
I came across a few related questions, but they weren't helpful for an inexperienced developer like myself: How to get UIMenuController work for a custom view?, How to paste image from pasteboard on UITextView?