在UILabel中加图片

// 最后的文字

NSMutableAttributedString * attri = [[NSMutableAttributedString alloc]init];

// 文字

NSMutableAttributedString * attri1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@" %@",_analyseModel.Address]];

NSTextAttachment *attch = [[NSTextAttachment alloc] init];

attch.image = [UIImage imageNamed:@"addressImage"];

attch.bounds = CGRectMake(0, -2, 10, 14);

// 将图片加到文字中

NSAttributedString * string = [NSAttributedString attributedStringWithAttachment:attch];

// 拼接文字

[attri appendAttributedString:string];

[attri appendAttributedString:attri1];

if (![_analyseModel.Address isEqualToString:@""]) {

_companyAddress.attributedText = attri;

}

你可能感兴趣的:(在UILabel中加图片)