图文结合/在label前后插入图片。
2016-09-14 本文已影响112人
夏日里的夏天
在label中插入图片
NSMutableAttributedString *labelStr = [[NSMutableAttributedString alloc] initWithString:model.buyer_goods_name];
// 添加表情
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
// 表情图片
attch.image = [UIImage imageNamed:@"woxiangyao"];
// 设置图片大小
attch.bounds = CGRectMake(0, 0, 36, 13);
// 创建带有图片的富文本
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
// [attri appendAttributedString:string];//这是加在最后面的
[labelStr insertAttributedString:string atIndex:0];//这是插入图片的位置
// 用label的attributedText属性来使用富文本
cell.titleLabel.attributedText = labelStr;

2.改变label的字体颜色