使用 iOS 将文本复制到剪贴板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1479468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy text to clipboard with iOS
提问by tarnfeld
What is the best way to copy text to the iPhone's clipboard in your application?
将文本复制到应用程序中 iPhone 剪贴板的最佳方法是什么?
Their docs are sketchy and have way more features than what I want... I just want to set a string as the users clipboard.
他们的文档很粗略,并且具有比我想要的更多的功能......我只想将一个字符串设置为用户剪贴板。
回答by samvermette
Although the accepted answer is a good walkthrough of how UIPasteboard
works, I figured I'd post the relevant snippet right here for everyone's convenience:
虽然接受的答案是一个很好的UIPasteboard
工作原理演练,但我想我会在这里发布相关的片段,以方便大家:
OBJ-C
OBJ-C
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"paste me somewhere";
Swift 2.2
斯威夫特 2.2
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
Swift 3+:
斯威夫特 3+:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"
回答by Mojtabye
Swift 2.2 :
斯威夫特 2.2:
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
Swift 3:
斯威夫特 3:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"