Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy image and text to the UIPasteboard

I want to copy image and text (both) to UIPasteBoard. Is it possible to copy both the text and image.

Here I can copy image only or text only . How to copy both ?

My code for copy image is as follows,

UIPasteboard *pasteBoard = [UIPasteboard pasteboardWithName:UIPasteboardNameGeneral create:NO];
pasteBoard.persistent = YES;
NSData *data = UIImagePNGRepresentation(newImage);
[pasteBoard setData:data forPasteboardType:(NSString *)kUTTypePNG]; 

Thanks in advance !!!!!

like image 508
Vijay Avatar asked Nov 29 '22 17:11

Vijay


1 Answers

Here is my code and it is working perfectly on my device.

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = NO;

NSMutableDictionary *text = [NSMutableDictionary dictionaryWithCapacity:1];
[text setValue:captionLabel.text forKey:(NSString *)kUTTypeUTF8PlainText];

NSMutableDictionary *image = [NSMutableDictionary dictionaryWithCapacity:1];
[image setValue:gratitudeImageView.image forKey:(NSString *)kUTTypePNG];

pasteboard.items = [NSArray arrayWithObjects:image,text, nil];
like image 54
Shahid Iqbal Avatar answered Dec 01 '22 06:12

Shahid Iqbal