ioscocoa-touchcopy-pasteuipasteboard

How to copy UIImage data to clipboard/UIPasteboard? And how do I test it?


I tried to use the following code to copy the Image data to UIPasteboard on click of the Copy item in the menu.

UIPasteboard *gpBoard = [UIPasteboard generalPasteboard];
[[gpBoard setData:UIImageJPEGRepresentation(imgView.image, 1.0) forPasteboardType:UIPasteboardTypeListImage];

Which parameter i have to send for forPasteboardType:, and how to test after copying the data?


Solution

  • It's a lot easier:

    [UIPasteboard generalPasteboard].image = imgView.image;
    

    To get the image out again:

    UIImage *image = [UIPasteboard generalPasteboard].image;