Omkar Jadhav
Omkar Jadhav

Reputation: 504

Copy Text to Clipboard (Pasteboard) from UITextView via UIButton?

Is there any way to copy text from a TextView that has User Interaction is enabled to the clipboard via a UIButton?

But instead of the user holding down his finger on the uitextview so that the apple standard window popups to copy I want the user to be able to do with just the click of the button .. (Whole text)

Regards,

Upvotes: 9

Views: 6872

Answers (2)

kennytm
kennytm

Reputation: 523224

In the button's target action, call

[UIPasteboard generalPasteboard].string = uiTextView.text;

Upvotes: 25

schaechtele
schaechtele

Reputation: 1130

You could take the actual UIView, that the current UIViewController shows and loop through the subviews to get all UITextView's that have user interaction enabled. Or do you have only one textview?

You can get the text of a UITextView with its text property and copy this text with the method KennyTM described above:

[UIPasteboard generalPasteboard].string = yourTextView.text;

Upvotes: 3

Related Questions