I have a text-view with some text and a copy button in that view,
When the user enters some text and presses the copy button, it needs to copy that text and paste that text wherever he wants.
I know there is a default copy/paste menu-controller in iOS, but I want to do this functionality in a button click. I think there is UIPasteboard
to do this functionality, but I don't know how to use it.
Swift
This is the Swift version of the accepted answer.
Copy
Paste
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 ;-)
I suspect you can relatively easily do what you want, starting with the
[UIPasteboard dataForPasteboardType:]
method.There's Apple sample code you can look into at:
http://developer.apple.com/library/ios/#samplecode/CopyPasteTile/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009040
Not sure why we can't simply use:
as per UIResponder docs
To copy from a button click:
To paste from a button click: