uilabel和uitextview的图文混排是相同的
代码示例(uilabel作为示例)
UILabel *tempLabel = [[UILabel alloc] init];
tempLabel.font = Font(15);
//设置富文本
NSMutableAttributedString *attributeStr1 = [[NSMutableAttributedString alloc] initWithString:TITLENAME];
NSDictionary *attributeDict = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:12],NSFontAttributeName,
BYColorff3333,NSForegroundColorAttributeName,nil];
[attributeStr1 addAttributes:attributeDict range:NSMakeRange(0, attributeStr1.length)];
//添加图片
NSTextAttachment *attach = [[NSTextAttachment alloc] init];
attach.image = [UIImage imageNamed:@"icon_index_arrow_right"];
attach.bounds = CGRectMake(-5, -2, 12, 12);
NSAttributedString *attributeStr2 = [NSAttributedString attributedStringWithAttachment:attach];
[attributeStr1 insertAttributedString:attributeStr2 atIndex:0];
tempLabel.attributedText = attributeStr1;