美文网首页
在UILabel中加图片

在UILabel中加图片

作者: _桃夭大人_ | 来源:发表于2016-07-13 10:00 被阅读332次

// 最后的文字

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中加图片

      本文链接:https://www.haomeiwen.com/subject/dwmsjttx.html