Closed satyamub closed 8 years ago
See #12
@YuAo That I know how to do it however I am not able to know where do it!!!
Display icons in textview is not included in this lib. You need to do it yourself. You can try to fork this project and change the textToInput
property of WUEmoticonsKeyboardKeyItem
to a NSAttributedString
, so that you can assign a text attachment(which can be the image you want to display) to the textToInput
. Then modify the inputText:
method of WUEmoticonsKeyboard
to insert the attributed string textToInput
to your text view.
Hi @YuAo Even I tried that too
however found that [self.textInput replaceRange:range withText:attributedString]; does not accept the attributed string but normal string!!
@satyamub Right, you need to convert the textInput property to a textview or textfield based on your app's context.
An alternate solution is to use a text view that supports parsing emotion texts, for example, https://github.com/fsjack/JKRichTextView
If this feature does not work, then there is no use of this library either!!!
Okay @YuAo ...I am trying !!
You can also choose not to use this library : )
@YuAo I did not mean that. I have tried converting the textInput to TextView and then tried to insert the image through the below code
if ([self.textInput isKindOfClass:UITextView.class]) { UITextView textView = (UITextView )self.textInput; NSMutableAttributedString attributedString = [[NSMutableAttributedString alloc] initWithString:@" "]; NSTextAttachment textAttachment = [[NSTextAttachment alloc] init]; textAttachment.image = [UIImage imageNamed:@"weico.png"]; UIImage *myIcon = [WUEmoticonsKeyboard imageWithImage:textAttachment.image scaledToSize:CGSizeMake(20, 20)];
textAttachment.image = myIcon;
//I'm subtracting 10px to make the image display nicely, accounting
//for the padding inside the textView
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
[attributedString replaceCharactersInRange:NSMakeRange(1, 0) withAttributedString:attrStringWithImage];
textView.attributedText = attributedString;
}
Its inserting the emoticons however its inserting the image once...
So, what is your point? It seems that you've successfully inserted the image.
Yes thats true however when next time I press the image, it replacing all texts with image again. There must be something like cursor needs to be set.
It is you who replaced all the texts with the image. You just set the entire attributed text of the text view to the attributed string with image attachment.
What you should do is to use the selectedTextRange
or selectedRange
property of the text view. selectedTextRange
/selectedRange
can help you find the cursor's current location. You should only replace(or insert to) the "selected" part of the text view's content with your image attached attributed string.
If you don't know what to do, read the documentation, search on google, or head to sites like stackoverflow.
Thanks sir.. if you could help me in code.. The help will be much appreciated..
Hi @YuAo ... If i will select a Emoticons in in keyboard, I want to show that in TextView... How can I show that? Now its showing only text of the selected emoticons