テキストと一緒に画像 (絵文字) を送信する必要があるチャット アプリケーションがあります。これで、 (コードの下)
を介して画像を追加できますNSTextAttachment
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
NSString *img=[NSString stringWithFormat:@"%@.png",imgName];
textAttachment.image =[UIImage imageNamed:img];
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
NSMutableAttributedString *nStr=[[NSMutableAttributedString alloc]initWithAttributedString:_txtChat.attributedText];
[nStr appendAttributedString:attrStringWithImage];
_txtChat.attributedText =nStr;
今、私が望むのは、「:)
」というカスタムテキストをスマイルアイコンに付けて、呼び出し時に_txtChat.text
:) の代わりに . が返されるようにすることUIImage
です。したがって、ユーザーが を見た場合Hii <Smilie>
、私は を取得し"Hii :)"
ます。入手可能か判断がつきません。