gpt4 book ai didi

iphone - 将图像和文本复制到 UIPasteboard

转载 作者:行者123 更新时间:2023-12-03 19:02:58 27 4
gpt4 key购买 nike

我想将图像和文本(两者)复制到 UIPasteBoard。是否可以同时复制文本和图像。

这里我可以仅复制图像或仅复制文本。如何复制两者?

我的复制图像代码如下,

UIPasteboard *pasteBoard = [UIPasteboard pasteboardWithName:UIPasteboardNameGeneral create:NO];
pasteBoard.persistent = YES;
NSData *data = UIImagePNGRepresentation(newImage);
[pasteBoard setData:data forPasteboardType:(NSString *)kUTTypePNG];

提前致谢!!!!

最佳答案

这是我的代码,它在我的设备上完美运行。

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = NO;

NSMutableDictionary *text = [NSMutableDictionary dictionaryWithCapacity:1];
[text setValue:captionLabel.text forKey:(NSString *)kUTTypeUTF8PlainText];

NSMutableDictionary *image = [NSMutableDictionary dictionaryWithCapacity:1];
[image setValue:gratitudeImageView.image forKey:(NSString *)kUTTypePNG];

pasteboard.items = [NSArray arrayWithObjects:image,text, nil];

关于iphone - 将图像和文本复制到 UIPasteboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7658307/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com