致敬YYText的作者,YYText的Swift版本

Objecttive-C version of YYText添加链接描述

本项目写了YYTextView仿微信输入高度动态变化YYTextView限制输入字数YYLabel之Html富文本超链接检测及点击YYLabel之评论盖楼等四个示例。

扩展了YYLabel设置Html富文本方法

// MARK: - 添加html富文本配置扩展
extension YYLabel {/***  设置html富文本,*  由于html转换属于耗时超时操作,异步后台处理*  假如是列表,转换完成后再刷新对应的Cell,否则会照成滚动卡顿*/func yy_setHtmlAttributedString(text: String, font: UIFont, lineSpacing: CGFloat, color: UIColor = .black, linkColor: UIColor = .blue, alignment: NSTextAlignment? = nil, completion: ((NSMutableAttributedString?, Bool) -> Void)? = nil) {let defAttri = NSMutableAttributedString(string: text)defAttri.yy_color = colordefAttri.yy_font = fontdefAttri.yy_lineSpacing = lineSpacingattributedText = defAttriDispatchQueue.global().async {var res:NSMutableAttributedString?if let data = text.data(using: .unicode) {do {let attributed = try NSMutableAttributedString.init(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)attributed.yy_lineSpacing = lineSpacingattributed.yy_color = colorattributed.yy_font = fontattributed.yy_alignment = alignment ?? .leftattributed.enumerateAttributes(in: attributed.yy_rangeOfAll, options: .reverse) { keys, range, _ inkeys.forEach { i inif i.key.rawValue == "NSLink" {let highlight: YYTextHighlight = YYTextHighlight()highlight.color = linkColorhighlight.yy_tapAction { _, _, _, _ inlet link = "\(i.value)"UIApplication.shared.open(URL(string: link)!, options: [:], completionHandler: nil)}attributed.yy_set(color: linkColor, range: range)attributed.yy_set(textHighlight: highlight, range: range)attributed.yy_set(underlineStyle: NSUnderlineStyle.single, range: range)}}}res = attributed} catch _ {}}DispatchQueue.main.async {self.attributedText = rescompletion?(res, false)}}}
}

扩展了YYLoad,Runtime方法交换的实现方案

protocol YYLoad: Any {static func runOnce()
}extension UIViewController:YYLoad {static func runOnce() {/// 这里写了两个示例给大伙看YYExchangeMethod(self, #selector(viewWillAppear(_:)), #selector(yy_viewWillAppear(_:)))YYExchangeMethod(self, #selector(touchesBegan(_:with:)), #selector(yy_touchesBegan(_:with:)))}@objc func yy_viewWillAppear(_ animated: Bool) {yy_viewWillAppear(animated)}@objc func yy_touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {view.endEditing(false)}
}

扩展了YYTextView输入回调textViewWordCountChange

func textViewWordCountChange(_ textView: YYTextView, count: Int) {print("当前输入了\(count)个字")
}

github地址

YYText-swift,swift版的YYText,优化了yylabel和yytextview的部分扩展相关推荐

  1. iOS8开发视频教程Swift语言版-Part 11:访问Web Service-关东升-专题视频课程

    iOS8开发视频教程Swift语言版-Part 11:访问Web Service-15288人已学习 课程介绍         本课程介绍了,iOS开发中,客户端与服务器端网络通信,介绍了XML和Js ...

  2. iOS8开发视频教程Swift语言版-Part 9:iOS分层架构设-关东升-专题视频课程

    iOS8开发视频教程Swift语言版-Part 9:iOS分层架构设-8532人已学习 课程介绍         传统企业级项目开发需要低耦合性,那么iOS这种相对比较小的应用开发需要么?答案是肯定的 ...

  3. iOS8开发视频教程Swift语言版-Part 10:iOS的数据持久化-关东升-专题视频课程

    iOS8开发视频教程Swift语言版-Part 10:iOS的数据持久化-17164人已学习 课程介绍         本课程主要介绍了iOS数据持久化的方式,沙箱目录,以及属性列表和对象归档,并且重 ...

  4. 扫描版模糊pdf优化方法

    扫描版模糊pdf优化方法 前言 扫描版的 pdf 文件,是学习生活非常常见.但是由于 pdf 文件制作水平良莠不齐.有时 pdf 文件显得模糊不堪,严重影响阅读心情,那么该如何优化这样的 pdf 文件 ...

  5. Introducing Swift(Swift介绍及其API)

    Home / OpenStack Swift / OpenStack Swift Architecture http://www.swiftstack.com/openstack-swift/arch ...

  6. 每天学一点Swift——Swift简介以及Xcode入门使用

    一.  Swift语言简介 Swift简洁但是不简单. Swift并不是弱类型的语言. Swift并不是一种脚本语言. Swift和Object-C各有轻重. 二.下载和安装Xcode 安装Xcode ...

  7. linux 网页另存为pdf,zhtmltopdf v0.2版发布 url页面转存为pdf或image扩展

    zhtmltopdf v0.2版发布 url页面转存为pdf或image扩展 发布时间:2014-06-05 21:24:24来源:红联作者:empast zhtmltopdf 是一个把 url页面转 ...

  8. Swift - 表格图片加载优化(拖动表格时不加载,停止时只加载当前页图片)

    列表的单元格中包含有图片在开发中很常见.通常我们可以直接在tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIn ...

  9. Swift之深入解析Xcode13对Swift对象生命周期的优化

    在 Xcode13 中,在 Build Setting 中,新增 Optimize Object Lifetimes 编译选项,默认是关闭的,Apple 建议将该选项设置为 YES,打开此优化项,可以 ...

  10. vscode安装swift插件_使用 Webpack 优化 VS Code 插件加载性能

    Webpack 这一 JS 模块打包神器相信大家都不陌生了.由于 VS Code 插件大部分也都是 JS/TS 代码 + 依赖库的形式,因此也可以使用 Webpack 打包,优化性能. 经过实测,经过 ...

最新文章

  1. 图的基本操作实现(数据结构实验)
  2. exit()函数学习
  3. 关于Modernizr的使用
  4. 解剖几个有点难度的C笔试题
  5. Python实现主成分分析(PCA)降维:原理及实例分析
  6. 在spring boot中3分钟上手RPC框架Dubbo
  7. ES6 Map 数据结构、ES6 箭头函数
  8. 使用sql语句查询access数据库
  9. Adobe Reader X 10.1.0
  10. 微信公众号模板消息推送
  11. ubuntu16.04安装rabbitVCS
  12. Mapstruct使用介绍
  13. python apscheculer 报错 skipped: maximum number of running instances reached (1)
  14. iOS 13越狱:越狱后如何安装AppSync和afc2越狱补丁
  15. 推荐系统与LSTM、GRU
  16. 如何写好软件项目的工作计划(一)
  17. 10分钟就能完成别人半天的工作量,Word长文档排版技巧分享
  18. 软件测试面试题:对杯子进行测试用例设计?
  19. python 地址簿
  20. mysql describe什么意思_MySQL中describe命令的使用方法小结_MySQL

热门文章

  1. css div 分页样式,3种简洁漂亮的CSS分页按钮样式
  2. 时间序列分析实验报告总结_时间序列分析实验报告
  3. HttpModule 与 Globle.asax
  4. linux 固态硬盘 分区工具,固态硬盘怎么分区?使用免费分区助手轻松搞定!
  5. html代码实现简单的简历模板
  6. 华为USG6000V防火墙学习
  7. 快速地将SolidWorks模型导入Adams
  8. e320/t420/w520等 qm67/hm65/hm67等 6系芯片组更新BIOS以安装三代酷睿cpu提升性能的想法
  9. Echarts直方图
  10. msfconsole常用搜索命令search