iOS UILable 文字添加图片 (文字前面,中间,后面添加图)

1,实例化一个UILable

2,

 // 创建一个富文本

    NSMutableAttributedString *attri =     [[NSMutableAttributedString alloc] initWithString:@"超时罚款24元/小时"];

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

    // 表情图片

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

    // 设置图片大小

    attch.bounds = CGRectMake(0, 0, 30/2, 27/2);

    // 创建带有图片的富文本

    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];

[attri appendAttributedString:string]; //在文字后面添加图片

 //在文字下标第几个添加图片  0就是文字前面添加图片

      [attri insertAttributedString:string atIndex:0]; 

    // 用label的attributedText属性来使用富文本

    实例化的lable.attributedText = attri;