textAttachment unavailable in ASTextNode2
Hello Guys, I found that the NSTextAttachment is not visible as I set the ASTextNode2.truncationMode with NSLineBreakByTruncatingTail.
The ASTextNode2.attributedText property description says that
For inline image attachments, add an attribute of key NSAttachmentAttributeName, with a value of an NSTextAttachment.
I added NSAttachmentAttributeName to ASTextNode2.attributedText, it doesn’t work though. Any ideas to make NSTextAttachment visible in ASTextNode2?
ASTextNode2 *textNode = [ASTextNode2 new];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:content ?: @"" attributes:@{
NSFontAttributeName : contentFont,
NSForegroundColorAttributeName : contentTextColor
}];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage as_imageNamed:answerIconName];
textAttachment.bounds = CGRectMake(0, -2, [UIImage as_imageNamed:answerIconName].size.width, [UIImage as_imageNamed:answerIconName].size.height);
NSAttributedString *attachmentAttributedString = [NSAttributedString attributedStringWithAttachment:textAttachment];
NSMutableAttributedString *mutableAttachmentAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:attachmentAttributedString];
[mutableAttachmentAttributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@" " attributes:nil]];
[mutableAttachmentAttributedString addAttribute:NSAttachmentAttributeName value:textAttachment range:NSMakeRange(0, mutableAttachmentAttributedString.length)];
[attributedString insertAttributedString:mutableAttachmentAttributedString atIndex:0];
textNode.attributedText = attributedString;
textNode.userInteractionEnabled = YES;
textNode.maximumNumberOfLines = _maxLineCount;
textNode.truncationMode = NSLineBreakByTruncatingTail;
textNode.additionalTruncationMessage = [[NSAttributedString alloc] initWithString:@"...unfold" attributes:@{
NSFontAttributeName : contentFont,
NSForegroundColorAttributeName : SRGBCOLOR_HEX(0x4769a9)
}];
textNode.delegate = self;
I found a tricky way to do this. NSMutableParagraphStyle.firstLineHeadIndent can be used to make space for the attachment image. And you can overlay the attachment image on the ASTextNode2 at the firstLineHeadIndent place.
I meet the same problem, any other idea can fix this issue?
same issue. YYLabel is fine, ASTextNode and ASTextNode2 is broken.


