简体   繁体   中英

How can I set image in textDocumentProxy with custom keyboard extension iOS 8?

How can we set an image behalf of the text?

Following code is to display text in the input view:

[self.textDocumentProxy insertText:[key currentTitle]];

My code of paste board to display the image :

NSData *imgData = UIImagePNGRepresentation(image);
[pasteBoard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
NSString* newStr = [[NSString alloc] initWithData:imgData encoding:NSUTF8StringEncoding];
[self.textDocumentProxy insertText:[pasteBoard string]];

I have created a pasteboard with the images just I have to display the images in to input view.

See this picture for the concept :

在此输入图像描述

Note:

I have to select image from keyboard and show in inputview not to copy paste from library.

If anyone know please reply as answer or any suggestion will also acceptable.

Thanks!

I don't think it's possible to add directly an image from a custom keyboard. A workaround would be to copy the image to the pastboard and paste it in the destination area. (It's not very nice but It's the only way I see actually)

I have get solution for this question use clipboard copy and paste

Code :

UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSData *data = [self.Videoassets objectAtIndex:btn.tag];
NSLog(@"File size is : %.2f MB",(float)data.length/1024.0f/1024.0f);
[pasteBoard setData:data forPasteboardType:@"public.mpeg-4"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM