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.
他们的文档很粗略,而且比我想要的功能更多……我只想设置一个字符串作为用户剪贴板。
2 个解决方案
#1
527
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!"
#2
27
Swift 2.2 :
斯威夫特2.2:
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
Swift 3:
斯威夫特3:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"
#1
527
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!"
#2
27
Swift 2.2 :
斯威夫特2.2:
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
Swift 3:
斯威夫特3:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"