본문 바로가기

Development/IOS & Mac

UIPasteBoard 사용방법

기본적으로 UIPasteboard 어플리케이션에서 공유해서 사용이 가능하다. 몇가지 사용방법을 소개하자면..


UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
appPasteBoard.persistent = YES;
[appPasteBoard setString:@"STRING TO COPY"];

UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
yourTextField.text = [appPasteBoard string];


UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyPaste" create:YES];
appPasteBoard.persistent = YES;
NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"COPIED.jpg"]);
[appPasteBoard setData:data forPasteboardType:@"com.yourCompany.yourApp.yourType"];


UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyPaste" create:YES];
NSData *data = [appPasteBoard dataForPasteboardType:@"com.yourCompany.yourApp.yourType"];
imageView.image = [UIImage imageWithData:data];