Copy Image with UIPasteBoard (Swift)

被刻印的时光 ゝ 提交于 2019-12-03 00:36:55
user2277872

Try using this code:

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

you can find out how this works here!

Hope this helps

When using UIPasteboard.generalPasteboard().image = image; it seems the image is not copied to the pasteboard. Instead try the next code, it also explains how you can replace "public.png" string:

// The Pasteboard is nil if full access is not granted
// 'image' is the UIImage you about to copy to the pasteboard
if let pb = UIPasteboard.generalPasteboard() {
    let type = UIPasteboardTypeListImage[0] as! String
    if !type.isEmpty {
        pb.setData(UIImagePNGRepresentation(image), forPasteboardType: type)
        if let readData = pb.dataForPasteboardType(type) {
            let readImage = UIImage(data: readData, scale: 2)
            println("\(image) == \(pb.image) == \(readImage)")
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!