Monday, June 23, 2014

Copy a combination of image and text in IOS - UIPasteboard

A sample code snippet to copy a combination of image and text in IOS - UIPasteboard.

 NSMutableDictionary *photo = [NSMutableDictionary dictionary]; 
 NSMutableDictionary *text = [NSMutableDictionary dictionary]; 
 UIImage *image1 = [UIImage imageNamed:@"myimage.png"]; 
 NSData* imageData = UIImagePNGRepresentation(image1); 
 [photo setValue:imageData forKey:(NSString*)kUTTypePNG]; 
 [text setValue:@"Test String" forKey:(NSString *)kUTTypeUTF8PlainText]; 
 [[UIPasteboard generalPasteboard] setItems:[NSArray arrayWithObjects:photo, text, nil]];