Tuesday 13 May 2014

Working with UIPasteboard

Hi friends in this tutorial  we will cover how to deal with UIPasteBoard.We will cover these much tasks:


1> Reading data  from general PasterBoard
2> Writing data to general PasteBoard
3> create Pasteboard
4> remove Pasteboard


1> Reading data from general PasteBoard

if you want to read string from general pasteboard

NSString *strName = [UIPasteboard generalPasteboard].string

2> Writing  data to general PasteBoard

 [[UIPasteboard generalPasteboard]setString:@"Mittal"];

 UIImage * image=[UIImage imageWithContentsOfFile:@"FILE_PATH"];
 UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setImage:image];

//Method 2
NSData *imageData = UIImagePNGRepresentation(image);
[pasteboard setData:imageData forPasteboardType:(NSString *)kUTTypePNG];

You can also set dictionary to the clipboard this way,

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];


3> Create Custom PasteBoard

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"customPasteBoard" create:YES];

 [pasteboard setPersistent:YES];
 //save the unique identifier string that we created earlier 
[pasteboard setString:@"Mittal"];

4> Remove PasteBoard

[UIPasteboard removePasteboardWithName:@"customPasteBoard"];

1 comment:

  1. How to Play the Sega Genesis Video Game Classic for Fun
    The Sega Genesis 바카라사이트 is 우리카지노 an all-in-one home video game console released in 1991 for the Sega Mega Drive/Genesis console. It features over 40 games,

    ReplyDelete