SwiftUI - 如何将文本复制到剪贴板? [英] SwiftUI - how to copy text to clipboard?

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

问题描述

如何将文本字段的内容复制到 iOS 剪贴板?

How does one copy the contents of a Text field to the iOS clipboard?

我有以下代码 &想要将print(..)"语句替换为将文本字段的内容复制到 iOS 剪贴板的语句.

I have the following code & want to replace the "print(..)" statement with a statement that copies the content of the text field to the iOS clipboard.

Text(self.BLEinfo.sendRcvLog)
    .onTapGesture(count: 2) {
        print("Copy text field content to ClipBoard Here..")
    }

似乎找不到如何执行此操作的任何 SwiftUI 示例.

Can't seem to find any SwiftUI examples how to do this.

谢谢!

推荐答案

使用以下内容

import MobileCoreServices // << for UTI types

// ... other code

Text(self.BLEinfo.sendRcvLog)
    .onTapGesture(count: 2) {
        UIPasteboard.general.setValue(self.BLEinfo.sendRcvLog, 
            forPasteboardType: kUTTypePlainText as String)
    }

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

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