iOS 图文混排(swift)
来源:互联网 发布:xp添加网络共享打印机 编辑:程序博客网 时间:2024/06/06 10:58
//// ViewController.swift// ImageText//// Created by fe on 2017/4/3.// Copyright © 2017年 fe. All rights reserved.//import UIKitclass ViewController: UIViewController { //展示文本的标签 @IBOutlet weak var textLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() let str1 = NSAttributedString(string: "今天的月亮很圆", attributes: [NSForegroundColorAttributeName : UIColor.red]) let str2 = NSAttributedString(string: "晚安", attributes: [NSForegroundColorAttributeName : UIColor.purple]) let attachment = NSTextAttachment() attachment.image = UIImage(named: "w_yueliang") let font = textLabel.font attachment.bounds = CGRect(x: 0, y: -4, width: (font?.lineHeight)!, height: (font?.lineHeight)!) let imageStr = NSAttributedString(attachment: attachment) let mstr = NSMutableAttributedString() mstr.append(str1) mstr.append(imageStr) mstr.append(str2) textLabel.attributedText = mstr }}
效果如下图:
0 0
- iOS 图文混排(swift)
- iOS swift-UILabel/UITextView的图文混排
- SWIFT实现图文混排
- 简单图文混排swift
- iOS图文混排
- IOS图文混排
- iOS图文混排
- Swift - 文本框textView图文混排的实现(附样例)
- swift实现简单的图文混排
- iOS coreText 图文混排
- IOS CoreText --- 图文混排
- IOS CoreText --- 图文混排
- iOS 实现图文混排
- iOS NSTextAttachment - 图文混排
- ios 图文混排 (支持显示文字和表情)
- iOS 之 图文混排(富文本)
- iOS 字符中插入按钮(简单图文混排)
- iOS实现简单图文混排效果
- 时间观念是大学生第一道面试题
- 估算
- eclipse.ini配置详情
- [bash]基础shell命令总结
- 屏幕常亮的三种方法
- iOS 图文混排(swift)
- 5、Linux进程和线程编程
- Linux磁盘分区
- 毕业去大公司还是小公司工作?如何看待网友的观点和你的选择?
- Mybatis源码分析 之 Configration
- 枚举排列各算法
- 【BZOJ 1208】【HNOI 2004】宠物收养所【treap】|【STL】
- 解决Navicat for Mysql mac 上的乱码问题
- 【SSM】Maven创建web项目:SpringMVC+Mybatis