码迷,mamicode.com
首页 > 其他好文 > 详细

label中添加图片

时间:2016-08-11 12:49:18      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

  • 创建NSTextAttachment的对象,用来装在图片
  • NSTextAttachment对象的image属性设置为想要使用的图片
  • 设置NSTextAttachment对象bounds大小,也就是要显示的图片的大小
  • [NSAttributedString attributedStringWithAttachment:attch]方法,将图片添加到富文本上

    //创建富文本字符串
    NSMutableAttributedString *mAString = [[NSMutableAttributedString alloc] initWithString:@"你好你好你好你好你好你好你你好你好你好你好你好你好你你好你好你好你好你好你好你"];
    //创建图片
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    attch.image = [UIImage imageNamed:@"ding"];
    attch.bounds = CGRectMake(0, -2, 16, 16);
    //将图片加入富文本
    NSAttributedString *imgString = [NSAttributedString attributedStringWithAttachment:attch];
    [mAString appendAttributedString:imgString];
    
    _Alabel.attributedText = mAString;
 
效果图:
技术分享
 
原文链接:http://www.jianshu.com/p/5828173adc3a

label中添加图片

标签:

原文地址:http://www.cnblogs.com/wlsxmhz/p/5760221.html

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