2015-11-02 55 views
1

它顯示null .custom鍵盤圖像通過textdocumentproxy發送。我想通過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]; 

回答

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"];