也不清楚什么原因,遇到同样问题的可以借鉴一下
直接使用下面的方法,图片显示不出来
NSTextAttachment *attchment = [[NSTextAttachment alloc] init];
attchment.image = [UIImage jy_imageNamed:@"1" context:self];
attchment.bounds = CGRectMake(0, 0, 14, 14);
//关键转义代码
NSMutableAttributedString *imageText= [NSAttributedString attributedStringWithAttachment:attchment];
[attStr replaceCharactersInRange:NSMakeRange(0, 1) withAttributedString:imageText];
之后使用这个可以显示
UIImageVIew *insertImageView = [[UIImageVIew alloc] initWithImage:[UIImage imageNamed:@"lesson_home_list_i"]];
insertImageView.frame = CGRectMake(0, 0, 14, 14);
//关键转义代码
NSMutableAttributedString *imageText= [NSMutableAttributedString attachmentStringWithContent:insertImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(14, 14) alignToFont:KBoldFont(20) alignment:YYTextVerticalAlignmentCenter]; // 图片转化为特殊字符
[attStr replaceCharactersInRange:NSMakeRange(0, 1) withAttributedString:imageText];
//表情文本转换成字符串文本
- (void)exchangeTextFromEmojiTextView:(YYTextView *)textView{
NSArray *arr = textView.textLayout.attachments;
NSArray<NSValue *> *values = textView.textLayout.attachmentRanges;
for (int i = 0; i < arr.count; i ++) {
NSValue *value = [values jy_objectAtIndex:i];
NSRange range = value.rangeValue;
YYTextAttachment *attachment = [arr jy_objectAtIndex:i];
JYMomentsEmojiImageView *imageView = attachment.content;
JYMomentsEmojiModel *model = imageView.model;
NSString *name = model.name;
NSLog(@"%ld %ld %@%@",range.location,range.length,model,name);
}
}
网友评论