From 02e816cd4615bb14ae4ea73377ca2786065da14d Mon Sep 17 00:00:00 2001 From: yuan Date: Wed, 11 Sep 2024 17:43:42 +0800 Subject: [PATCH] add-post --- ...el\345\257\214\346\226\207\346\234\254.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "_posts/2024-09-11-YYLabel\345\257\214\346\226\207\346\234\254.md" diff --git "a/_posts/2024-09-11-YYLabel\345\257\214\346\226\207\346\234\254.md" "b/_posts/2024-09-11-YYLabel\345\257\214\346\226\207\346\234\254.md" new file mode 100644 index 0000000..4d4c81d --- /dev/null +++ "b/_posts/2024-09-11-YYLabel\345\257\214\346\226\207\346\234\254.md" @@ -0,0 +1,38 @@ +--- +layout: post +title: YYLabel富文本 +subtitle: 富文本 +date: 2024-09-11 17:36:00 GMT+0800 +author: 920 +header-img: +catalog: true +stickie: false +tags: + - 富文本 +--- + + +#### 富文本显示 + +- 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]; + +``` + +[连接](https://yznote.github.io/2019/10/25/%E5%AF%8C%E6%96%87%E6%9C%AC/) \ No newline at end of file