【发布时间】:2016-03-22 03:25:33
【问题描述】:
我需要支持将图像粘贴到UITextView。将图像复制到剪贴板后,“Paste”选项似乎没有弹出。当剪贴板上有文本时会这样做。
这是在自定义UITextView 中覆盖paste 选项的方法。但我需要有关如何获得显示选项的帮助...
// 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];
}
}
我遇到了一些相关的问题,但它们对像我这样没有经验的开发人员没有帮助: How to get UIMenuController work for a custom view?, How to paste image from pasteboard on UITextView?
【问题讨论】:
标签: ios objective-c cocoa-touch uitextview uimenucontroller