How to copy string to clipboard

走远了吗. 提交于 2019-12-10 13:23:08

问题


How do you copy text to the clipboard in xcode? Currently, I am using the following code:

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:shareString];

When I try to paste this into another one of the simulator apps, I end up pasting the entire view controller code. ??? Thanks in advance!


回答1:


Did you refered this link : https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/UsingCopy,Cut,andPasteOperations/UsingCopy,Cut,andPasteOperations.html

The amount of code you have shared seems ok to copy text. May be more code will be helpful to understand your problem. Meanwhile you can go through this link , it is really helpful.




回答2:


In Swift 3.0 you can copy text on PasteBoard and paste anywhere. In short, if you want to copy text programmatically then below code will help you.

let pasteBoard = UIPasteboard.general
pasteBoard.string = "copy the text"


来源:https://stackoverflow.com/questions/19884243/how-to-copy-string-to-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!