博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
label中添加图片
阅读量:4608 次
发布时间:2019-06-09

本文共 788 字,大约阅读时间需要 2 分钟。

  • 创建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

转载于:https://www.cnblogs.com/wlsxmhz/p/5760221.html

你可能感兴趣的文章
Linux清屏命令
查看>>
Oracle 查询
查看>>
debug、release
查看>>
CrawlSpider源码分析
查看>>
开学第一节课测试感受
查看>>
<%@include和<jsp:include
查看>>
设计模式-系列索引
查看>>
c语言之控制语句:循环
查看>>
分析恶意驱动(进程启动apc注入dll)
查看>>
Unity你不知道的秘密
查看>>
从网页获取图片
查看>>
在Python程序中调用Java代码的实现
查看>>
数组经典操作总结
查看>>
Tarjan算法初探(2):缩点
查看>>
可变对象与不可变对象
查看>>
centOS解决乱码问题
查看>>
《大话设计模式》PDF
查看>>
Android开发从入门到精通pdf
查看>>
PYTHON编程 第4版 上册pdf
查看>>
DirBuster下载
查看>>