如何使用Swift将文本复制到剪贴板/粘贴板 [英] How to copy text to clipboard/pasteboard with Swift

查看:1172
本文介绍了如何使用Swift将文本复制到剪贴板/粘贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Swift新手寻找一个干净的例子,如何复制文本到iOS剪贴板,然后可以使用/粘贴在其他应用程序。

I'm a Swift newbie looking for a clean example of how to copy text to iOS clipboard that can then be used/pasted in other apps.

我假设键类别在UIPasteboard中,因此,但在其提供的代码示例中找不到相关区域: https ://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIPasteboard_Class/index.html

I am assuming that the key classes are in UIPasteboard, but can't find the relevant areas in the code example they supply: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIPasteboard_Class/index.html

任何帮助将非常非常感激!
感谢,
G

Any help would be very much appreciated! Thanks, G

推荐答案

如果你想要的只是纯文本, code> string 属性:

If all you want is plain text, you can just use the string property:

UIPasteboard.generalPasteboard().string = "Hello world"

在Swift 3中:

UIPasteboard.general.string = "Hello world"

这篇关于如何使用Swift将文本复制到剪贴板/粘贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆