How to do copy/paste function programmatically in iphone?
To copy from a button click:
- (IBAction)copy { UIPasteboard *pb = [UIPasteboard generalPasteboard]; [pb setString:[textView text]];}
To paste from a button click:
- (IBAction)paste { UIPasteboard *pb = [UIPasteboard generalPasteboard]; textView.text = [pb string];}
Swift
This is the Swift version of the accepted answer.
Copy
UIPasteboard.general.string = myTextView.text
Paste
if let myString = UIPasteboard.general.string { myTextView.insertText(myString)}
For developers using MonoTouch, here are the two lines I used to complete the task in C#.
The answer iscavenger provided to this question served as the model for my answer (after I successfully implemented it in my project ;-)
UIPasteboard clipboard = UIPasteboard.General;clipboard.String = "string being added to clipboard";