I am iOS application developer. I am working in iOS custom keyboard extension. I need to show some image in my custom keyboard, that I have already done. But tapping on that image the same image will be paste/send into the text area (UITextField or UITextView). I have done the below code for this:
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage imageNamed:@"Gun.png"];
CGFloat scaleFactor = 10;
textAttachment.image = [UIImage imageWithCGImage:textAttachment.image.CGImage scale:scaleFactor orientation:UIImageOrientationUp];
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
//[attributedString replaceCharactersInRange:NSMakeRange(6, 1) withAttributedString:attrStringWithImage];
[self.textDocumentProxy insertText:[NSString stringWithFormat:@"%@", attrStringWithImage]];
But the image is not showing in the text area. It will be veryhelpfull for me, if I get any positive feedback. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire