YYLabel富文本

富文本

920 发布: 2024/9/11 17:36 本文总阅读量

富文本显示

  • yylabel中不能使用NSTextAttachment来处理富文本

正确方案

UIImageView *imageV = [[UIImageView alloc] init];
imageV.frame = CGRectMake(0, -2, 15, 15);
imageV.image = emojiImage;
NSAttributedString *imageString = [NSAttributedString yy_attachmentStringWithContent:imageV contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(15, 15) alignToFont:_contentL.font alignment:YYTextVerticalAlignmentCenter];

_contentL.attributedText = imageString;

或者

UIImage *image = [UIImage imageNamed:@"壁纸-详情-编辑"];
NSMutableAttributedString *attachment = [NSMutableAttributedString yy_attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:CGSizeMake(15, 15) alignToFont:SYS_Font(15) alignment:(YYTextVerticalAlignment)YYTextVerticalAlignmentCenter];

连接