andrefurquin
andrefurquin

Reputation: 522

How can I copy a png image to clipboard in order to paste it in other app?

I'm developing a custom keyboard and I want to be able to copy the button image to clipboard (it's a png image). I've already tried something like UIPasteboard.generalPasteboard().image = UIImage(named: "dMk87zJ.png") when the button is pressed, but it doesn't work. I was only able to accomplish that with text. What am I doing wrong ? Application Test

Upvotes: 3

Views: 4284

Answers (1)

Amit Bhavsar
Amit Bhavsar

Reputation: 1273

Please use below code for copy and paste images.

NSData *data = [NSData dataWithContentsOfFile:filePath];
[pasteboard setData:data forPasteboardType:@"public.png"];

Its perfect work in all apps which allow paste functionality. Especially Notes app.

For UTI types use this link

Don't use below code

[UIPasteboard generalPasteboard].image = image;

I face issue with Notes app with this line of code to copy png image

Upvotes: 7

Related Questions