美文网首页
UIlabel 文字加图片富文本

UIlabel 文字加图片富文本

作者: 曾柏超 | 来源:发表于2018-07-19 09:45 被阅读22次

           NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:teamInfo.name];
            NSTextAttachment *attch = [[NSTextAttachment alloc] init];
            if (teamInfo.type == TSessionTeamTypeNormal) {
                attch.image = [UIImage imageNamed:@"team_name_tag_normal"];
            }else if (teamInfo.type == TSessionTeamTypeClock) {
                attch.image = [UIImage imageNamed:@"team_name_tag_checkin"];
            }else if (teamInfo.type == TSessionTeamTypeDelegate) {
                attch.image = [UIImage imageNamed:@"team_name_tag_contract"];
            }
            attch.bounds = CGRectMake(5, -2, 30, 16);
            NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
            [attri appendAttributedString:string];
//          [attri insertAttributedString:string atIndex:0];
            _lblTitle.attributedText = attri;

相关文章

网友评论

      本文标题:UIlabel 文字加图片富文本

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