1. 设置空心区域<显示特殊标签>
原理就是设置不显示文字的区域,用于显示图片的内容;
注意设置最大宽度,否则不会换行preferredMaxLayoutWidth
+ (YYTextContainer *)getLiveThemeTextContainer:(CGFloat)indent
{
//liveThemeLabel的宽度
CGFloat width = kScreen_Width - 175;
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, width, 60)];
UIBezierPath *headIndentPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, indent, 16)];
YYTextContainer *container = [YYTextContainer containerWithPath:path];
container.exclusionPaths = @[headIndentPath];
return container;
}
YYLabel *classNameLabel = nil;
_classNameLabel = [[YYLabel alloc] init];
_classNameLabel.text = @" --";
_classNameLabel.font = HQ_Font_Medium(14);
_classNameLabel.numberOfLines = 2;
//注意设置最大宽度,否则不会换行的
_classNameLabel.preferredMaxLayoutWidth = kScreen_Width - 175;
[_containView addSubview:_classNameLabel];
NSAttributedString *attri = xxxxxx;
YYTextContainer *container = [[self class] getLiveThemeTextContainer:indent];
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:attri];
classNameLabel.textLayout = layout;
网友评论