首页 > 移动平台 > 详细

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

时间:2017-09-27 12:27:02      阅读:555      评论:0      收藏:0      [点我收藏+]

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 文字添加图片 (文字前面,中间,后面添加图)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!