1. 多行设置preferredMaxLayoutWidth
不设置没法计算换行的位置
_studyNameLabel = [[YYLabel alloc] init];
_studyNameLabel.text = @"--";
_studyNameLabel.textColor = HexRGB(0x2A2C35);
_studyNameLabel.font = HQ_Font_Regular(14);
_studyNameLabel.numberOfLines = 0;
_studyNameLabel.preferredMaxLayoutWidth = kScreen_Width - 88;
[_containView addSubview:_studyNameLabel];
2. 文本嵌入图标 yy_attachmentStringWithContent
实质是把图标符号化成普通的文本
NSMutableAttributedString *studyStr = [[NSMutableAttributedString alloc] init];
if (model.revise) {
UIImage *leftImage = [UIImage imageNamed:@"csp_review_icon"];
NSMutableAttributedString *attachText= [NSMutableAttributedString yy_attachmentStringWithContent:leftImage contentMode:UIViewContentModeCenter attachmentSize:leftImage.size alignToFont:HQ_Font_Regular(14) alignment:YYTextVerticalAlignmentCenter];
[studyStr appendAttributedString:attachText];
[studyStr yy_appendString:@" "];
}
[studyStr yy_appendString:model.objName? model.objName:@""];
studyStr.yy_font = HQ_Font_Regular(14);
studyStr.yy_color = HexRGB(0x2A2C35);
studyStr.yy_lineSpacing = 6;
_studyNameLabel.attributedText = studyStr;
网友评论