美文网首页
YYLabel 2019-11-06

YYLabel 2019-11-06

作者: iOS打怪升级 | 来源:发表于2019-11-06 11:20 被阅读0次
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;

相关文章

网友评论

      本文标题:YYLabel 2019-11-06

      本文链接:https://www.haomeiwen.com/subject/gmfubctx.html