1.创建label,创建label的富文本
NSMutableAttributedString * attrubedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"小苹果小苹果小苹果小苹果"]];
2.创建并添加图片文本
NSTextAttachment * attach = [[NSTextAttachment alloc]init];
attach.image = [UIImage imageNamed:@"test"];
attach.bounds = CGRectMake(0, 0, 40, 15);
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attach]; //创建图片文本
[attrubedStr appendAttributedString:string]; //添加到末尾
// [attrubedStr insertAttributedString:string atIndex:0]; //也可插入到某个位置
3.添加到label上面
label.attributedText = attrubedStr;
网友评论