我想通过textdocumentproxy自定义键盘图像

时间:2015-11-02 10:08:22

标签: custom-keyboard

它显示null .custom键盘图像通过textdocumentproxy发送。

NSMutableAttributedString *mas;
NSTextAttachment* onionatt = [NSTextAttachment new];
onionatt.image = onions;
onionatt.bounds = CGRectMake(0,-5,onions.size.width,onions.size.height);
NSAttributedString* onionattchar = [NSAttributedString attributedStringWithAttachment:onionatt];

NSRange r = [[mas string] rangeOfString:@"onions"];
[mas insertAttributedString:onionattchar atIndex:(r.location + r.length)];
NSString *string =[NSString stringWithFormat:@"%@",mas];
[self.textDocumentProxy insertText:string];

1 个答案:

答案 0 :(得分:0)

您无法通过uitextdocumentproxy发送图片

在自定义键盘中,您必须在粘贴板中复制图像,然后使用以下代码手动粘贴到文本字段中:

NSString *shareImageName = @"cross.png";
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
UIImage *image = [UIImage imageNamed:shareImageName];
NSData *data = UIImagePNGRepresentation(image);
[pasteboard setData:data forPasteboardType:@"public.png"];