Copy text to clipboard with iOS

只愿长相守 提交于 2019-11-27 05:02:10

问题


What is the best way to copy text to the iPhone's clipboard in your application?

Their docs are sketchy and have way more features than what I want... I just want to set a string as the users clipboard.


回答1:


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:

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!"



回答2:


Swift 2.2 :

let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"

Swift 3:

let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"


来源:https://stackoverflow.com/questions/1479468/copy-text-to-clipboard-with-ios

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