我需要支持将图像粘贴到一个UITextView.将图像复制到剪贴板后,Paste似乎没有弹出" "选项.当剪贴板上有文本时它会这样做.
这是如何覆盖paste自定义中的选项UITextView.但是我需要帮助才能让选项显示出来......
// 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];
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到了一些相关的问题,但对于像我这样缺乏经验的开发人员来说,它们没有帮助: 如何让UIMenuController为自定义视图工作?,如何在UITextView上粘贴来自粘贴板的图像?