0

I am trying to make my emoji keyboard as default keyboard.I want to add my images (sticker) to the textview.I am using xcode6 that allow to make our keyboard as default keyboard for all app.I can add text to the textview when click on my sticker.but not able to add that sticker to my textview.

In short,I am trying to get access of textview to add images.

Your solutions are appreciated.Thanks in advance.

1 Answers1

0

You need to use NSAttributted String:

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"like after"];

NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage imageNamed:@"whatever.png"];

NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];

[attributedString replaceCharactersInRange:NSMakeRange(4, 1) withAttributedString:attrStringWithImage];

source: iOS 7 TextKit - How to insert images inline with text?

Community
  • 1
  • 1
Rajan Balana
  • 3,775
  • 25
  • 42
  • 1
    I have used the below code.it will add only 1 image and lost the previous one . [attributedString appendAttributedString:attrStringWithImage]; – user3587934 Oct 14 '14 at 09:52