在应用程序中将文本复制到iPhone剪贴板的最佳方法是什么?
他们的文档很粗略,并且具有比我想要的更多的功能......我只想将字符串设置为用户剪贴板。
答案 0 :(得分:562)
虽然接受的答案是UIPasteboard
如何运作的一个很好的演练,但我想我会在这里发布相关的片段以方便每个人:
OBJ-C
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"paste me somewhere";
Swift 2.2
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
Swift 3 +:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"
答案 1 :(得分:29)
Swift 2.2:
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
斯威夫特3:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"