使用UIPasteBoard(Swift)复制图像 [英] Copy Image with UIPasteBoard (Swift)

查看:214
本文介绍了使用UIPasteBoard(Swift)复制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近看到这个项目,用户可以从自定义键盘点击GIF,他们会看到一个复制的工具。我有一个问题:

I recently saw this project in which a user can tap on a GIF from a custom keyboard and they would see a "copied" toolip appear. I have one question:


  • 如何在产品中重现此工具提示 GIF教程

  • How does one reproduce this tooltip in the products GIF-Tutorial?

任何人都可以给我一些示例代码使用。我理解如何使用UIPasteboard和它的功能,但我不能让它工作,当我在这个函数中添加UTI类型public.png:(我注意到在Objective-c它的@ public.png ,但我放置了public.png我找不到在线为这个源)

Could anyone give me some sample code to work with. I understand how to use UIPasteboard and it's functions, but I can't seem to get it to work when I put in the UTI type "public.png" in this function: (I noticed in Objective-c it's "@public.png", but I placed "public.png" I couldn't find a source online for this)

 let imageURL = NSString(string:NSBundle.mainBundle().pathForResource("test", ofType: "png")!)
        var data = NSData(contentsOfURL: NSURL(string:imageURL)!)
        UIPasteboard.generalPasteboard().setData(data!, forPasteboardType: "public.png")


推荐答案

尝试使用此代码:

let image = UIImage(named: "myimage.png")
UIPasteboard.generalPasteboard().image = image;

您可以了解这是如何工作的这里!

you can find out how this works here!

希望这有助于

这篇关于使用UIPasteBoard(Swift)复制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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