UIlabel 文字加图片富文本
2018-07-19 本文已影响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;