iOS-Swift3富文本(UILable文本图文混排)
来源:互联网 发布:幼儿园手指快算法 编辑:程序博客网 时间:2024/05/11 21:11
转载注明出处:http://blog.csdn.net/qxuewei/article/details/53213636
介绍下iOS开发中常用的符文布图文混排
需求: 邱学伟是大帅哥(加个笑脸图片) 邱学伟:红色背景绿色字体加粗显示 是:蓝色字体 10号小字体 大帅哥:灰色42号字体
UILabel中显示结果:
原谅我跟哥们开玩笑起的low爆了的项目名
核心代码:
//需求 邱学伟是大帅哥(加个笑脸图片) 邱学伟:红色背景绿色字体加粗显示 是:蓝色字体 10号小字体 大帅哥:灰色42号字体 fileprivate func FuWenBenDemo() { //定义富文本即有格式的字符串 let attributedStrM : NSMutableAttributedString = NSMutableAttributedString() //邱学伟 let qiuxuewei : NSAttributedString = NSAttributedString(string: "邱学伟", attributes: [ NSBackgroundColorAttributeName : UIColor.red,NSForegroundColorAttributeName : UIColor.green, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 28.0)]) //(string: "邱学伟") //是 let shi : NSAttributedString = NSAttributedString(string: "是", attributes: [NSForegroundColorAttributeName : UIColor.blue, NSFontAttributeName : UIFont.systemFont(ofSize: 10.0)]) //大帅哥 let dashuaige : NSAttributedString = NSAttributedString(string: "大帅哥", attributes: [NSForegroundColorAttributeName : UIColor.lightGray, NSFontAttributeName : UIFont.systemFont(ofSize: 42.0)]) //笑脸图片 let smileImage : UIImage = UIImage(named: "d_hehe")! let textAttachment : NSTextAttachment = NSTextAttachment() textAttachment.image = smileImage textAttachment.bounds = CGRect(x: 0, y: -4, width: 22, height: 22) attributedStrM.append(qiuxuewei) attributedStrM.append(shi) attributedStrM.append(dashuaige) attributedStrM.append(NSAttributedString(attachment: textAttachment)) label.attributedText = attributedStrM }
完整项目链接:https://git.oschina.net/qxuewei/AttributedStringDemo
0 0
- iOS-Swift3富文本(UILable文本图文混排)
- iOS 富文本、图文混排
- 富文本-图文混排
- iOS 之 图文混排(富文本)
- label富文本 以及图文混排
- Android 富文本编辑器 图文混排
- Android 富文本编辑器 图文混排
- iOS_富文本的图文混排
- ios知识点总结——富文本实现图文混排
- ios知识点总结——富文本实现图文混排
- ios知识点总结——富文本实现图文混排
- ios知识点总结——富文本实现图文混排
- 小胖说事13--------NSTextAttachment富文本控件实现图文混排
- 富文本(图文混排)—— TextKit & CoreText
- NSTextAttachment富文本控件实现图文混排
- NSTextAttachment富文本控件实现图文混排
- Spannable的富文本显示(图文混排)
- NSTextAttachment富文本控件实现图文混排
- bzoj 1163: [Baltic2008]Mafia 网络流
- CodeForces 734D Anton and Chess 【模拟】
- 算法——First Missing Positive
- 第十二周项目5-迷宫问题之深度优先遍历算法
- 全栈必备MySQL性能调优
- iOS-Swift3富文本(UILable文本图文混排)
- 软件工程代码层面的一点理解
- 【小松教你手游开发】【unity实用技能】unity发包优化(android一键发包)
- Android 动态热修复
- C++学习笔记之const
- linux下SSH服务远程登入
- 小撸BGARefreshView 自定义控件
- EXCEL中所有函数的使用
- 第二节.Redis的安装