使用 iOS 将文本复制到剪贴板

发布于 2024-08-05 08:32:51 字数 92 浏览 4 评论 0原文

在应用程序中将文本复制到 iPhone 剪贴板的最佳方法是什么?

他们的文档很粗略,并且具有比我想要的更多的功能...我只想设置一个字符串作为用户剪贴板。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断肠人 2024-08-12 08:32:51

虽然接受的答案很好地说明了 UIPasteboard 的工作原理,但我想我应该在这里发布相关片段以方便大家:

Obj-C

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"Paste me!";

Swift 2.2

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

Swift 3+:

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

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

Swift 2.2

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

Swift 3+:

let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"
风月客 2024-08-12 08:32:51

斯威夫特 2.2 :

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

斯威夫特 3:

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

Swift 2.2 :

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

Swift 3:

let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文