【问题标题】:How to save a label's image to a UIPasteboard? Xcode如何将标签的图像保存到 UIPasteboard? Xcode
【发布时间】:2016-01-22 10:41:10
【问题描述】:
如何在 Objective C - Xcode 7.1 中将标签的图像保存到 UIPasteboard / 剪贴板?
我试过下面这段代码,但它只复制文本。
[UIPasteboard generalPasteboard].string = helloField.text;
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"paste me somewhere";
是否也可以复制图像,甚至只是自行复制图像?
【问题讨论】:
标签:
objective-c
xcode
uiimage
uilabel
uipasteboard
【解决方案1】:
是的,你可以做到。
您需要使用以下方法将一张图片放入原生 iOS 粘贴板:
UIImage *image = [UIImage imageNamed:@"img.png"];
[[UIPasteboard generalPasteboard] setImage:image];
您也可以将 UIImages 数组放入 UIPasteboard:
[[UIPasteboard generalPasteboard] setImages:arrayOfImages];
要了解更多信息,您可以阅读 Apple UIPasteboard class reference.