码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-09-27 13:20:16      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:图片   bounds   一个   ble   uilable   uila   gre   bsp   uil   

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;

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

标签:图片   bounds   一个   ble   uilable   uila   gre   bsp   uil   

原文地址:http://www.cnblogs.com/liaolijun/p/7601022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!