NSMutableAttributedString * attrubedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"哈哈哈哈"]];
NSTextAttachment * attach = [[NSTextAttachment alloc]init];
attach.image = [UIImage imageNamed:@"moren"];
//图片位置
attach.bounds = CGRectMake(0, 0, 40, 15);
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attach];
//将图片放在最后一位
[attri appendAttributedString:string];
//将图片放在第一位
// [attri insertAttributedString:string atIndex:0];
NSTextAttachment * attach = [[NSTextAttachment alloc]init];
self.nameLabel.attributedText = attrubedStr;
本文介绍了如何在iOS应用中利用NSMutableAttributedString和NSTextAttachment,实现在UILabel上显示富文本,包括插入图片并调整图片大小和位置。示例代码展示了将图片置于文本末尾和开头的方法。
1294





