标题标签问题:
1.如果标签在标题前面很好处理。
2.如果标签在标题后面,就需要考虑到标题换行的问题。这里用YYKit处理的。
效果如下:
BHgTA T 2018-11-22 143260.jpg
NSMutableAttributedString *mStr = [NSMutableAttributedString new];
// 设置tag标签
NSString *tagStr = [NSString stringWithFormat:@" %@ ", model.cate_name];
NSMutableAttributedString *mTagStr = [[NSMutableAttributedString alloc] initWithString:tagStr];
mTagStr.yy_font = FONT(9);
mTagStr.yy_color = ColorHex(0xF9860A);
YYTextBorder *border = [YYTextBorder new];
border.strokeColor = ColorHex(0xF9860A);
border.strokeWidth = 1;
border.lineStyle = YYTextLineStyleSingle;
border.cornerRadius = 2;
border.insets = UIEdgeInsetsMake(0, 1, 0, 1);
mTagStr.yy_textBorder = border;
[mStr appendAttributedString:name];
// 计算tag标签文字宽度
CGSize size = [tagStr ym_sizeWithFont:FONT(9) maxWidth:160];
// 新建一个tagv 用于生成图片
YYLabel *tagV = [YYLabel new];
tagV.attributedText = mTagStr;
tagV.width = size.width;
tagV.height = 20;
// 生成图片
UIImage *image = [UIImage getmakeImageWithView:tagV andWithSize:tagV.frame.size];
// 生成附件
NSMutableAttributedString *attachText = [NSMutableAttributedString yy_attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:image.size alignToFont:FONT(9) alignment:YYTextVerticalAlignmentCenter];
// 拼接文本
[mStr appendAttributedString:attachText];
self.yyNameLabel.attributedText = mStr;
网友评论