iOS 运用富文本在UILabel上显示图片

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,UILabel)