如何以编程方式复制NSData文件。我知道要复制文字很简单。
示例:
目标-C:
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:[textView text]];
如何设置它以便复制NSData值而不是文本。我正在尝试复制图像。
答案 0 :(得分:0)
您可以先将NSData转换为NSString&然后设置为pasteBoard
UIView.animateWithDuration(0.9, animations: { () -> Void in
答案 1 :(得分:0)
要复制图像,您可以执行以下操作:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"ImageName" ofType:@"png"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
[pasteboard setData:data forPasteboardType:@"imageName_public.png"];
粘贴图片可以简单地执行此操作:
UIImage *img = [UIPasteboard generalPasteboard].image;