YYKit 学习笔记之 YYLabel


使用Cocoapods安装YYKit
YYKit GitHub传送门:https://github.com/ibireme/YYKit
一.打开工程的 Podfile文件
二.在Podfile文件中添加pod ‘YYKit’, ‘~> 1.0.9’
三.终端进入工程目录,执行pod install

YYKit 添加成功

添加头文件
#import <YYKit/YYKit.h>

NSString *textStr = @"The YYLabel class implements a read-only text view,这是删除样式~~这是下划线样式~~这是带边框样式,这是带阴影样式,点击交互事件,添加点击事件,分割分割分割";YYLabel * label = [[YYLabel alloc] initWithFrame:CGRectZero];label.backgroundColor = [UIColor grayColor];label.numberOfLines = 0;label.textVerticalAlignment =  YYTextVerticalAlignmentTop;//垂直属性,上  下 或居中显示//富文本属性NSMutableAttributedString  * attriStr = [[NSMutableAttributedString alloc] initWithString:textStr];//设置行间距attriStr.lineSpacing = 10;attriStr.font = [UIFont systemFontOfSize:20];//富文本属性 NSRange range =[textStr rangeOfString:@"The YYLabel class implements a read-only text view"];[attriStr setFont:[UIFont boldSystemFontOfSize:30] range:range];//删除样式NSRange range2 =[textStr rangeOfString:@"这是删除样式" options:NSCaseInsensitiveSearch];YYTextDecoration *deletDecoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(1) color:[UIColor redColor]];[attriStr setTextStrikethrough:deletDecoration range:range2];//下划线NSRange range3 =[textStr rangeOfString:@"这是下划线样式" options:NSCaseInsensitiveSearch];YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(2) color:[UIColor yellowColor]];[attriStr setTextUnderline:decoration range:range3];//文本设置边框NSRange range4 = [textStr rangeOfString:@"这是带边框样式" options:NSCaseInsensitiveSearch];//边框YYTextBorder *border = [YYTextBorder new];border.strokeColor = [UIColor greenColor];border.strokeWidth = 1;border.lineStyle = YYTextLineStyleSingle;border.cornerRadius = 1;border.insets = UIEdgeInsetsMake(0, -2, 0, -2);[attriStr setTextBorder:border range:range4];//设置阴影NSRange range5 = [textStr rangeOfString:@"这是带阴影样式" options:NSCaseInsensitiveSearch];//阴影NSShadow *shadow = [[NSShadow alloc] init];[shadow setShadowColor:[UIColor redColor]];[shadow setShadowBlurRadius:1.0];[shadow setShadowOffset:CGSizeMake(2, 2)];[attriStr setShadow:shadow range:range5];//高亮显示文本 点击交互事件NSRange range6 =[textStr rangeOfString:@"点击交互事件" options:NSCaseInsensitiveSearch];YYTextBorder *border2 = [YYTextBorder new];border2.cornerRadius = 50;border2.insets = UIEdgeInsetsMake(0, -10, 0, -10);border2.strokeWidth = 0.5;border2.strokeColor = [UIColor yellowColor];border2.lineStyle = YYTextLineStyleSingle;[attriStr setTextBorder:border2 range:range6];[attriStr setColor:[UIColor greenColor] range:range6];YYTextBorder *highlightBorder = border2.copy;highlightBorder.strokeWidth = 1;highlightBorder.strokeColor =  [UIColor purpleColor];highlightBorder.fillColor =  [UIColor purpleColor];YYTextHighlight *highlight = [YYTextHighlight new];[highlight setColor:[UIColor orangeColor]];[highlight setBackgroundBorder:highlightBorder ];highlight.tapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {NSLog(@"点击事件");[self back];};[attriStr setTextHighlight:highlight range:range6];NSRange range7 =[textStr rangeOfString:@"添加点击事件" options:NSCaseInsensitiveSearch];YYTextHighlight *highlight2 = [YYTextHighlight new];[highlight2 setColor:[UIColor orangeColor]];//点击时字体颜色highlight2.tapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {NSLog(@"点击事件222");[self back];};[attriStr setTextHighlight:highlight2 range:range7];NSRange range8 =[textStr rangeOfString:@"分割分割分割"];[attriStr setFont:[UIFont boldSystemFontOfSize:25] range:range8];[attriStr setColor:[UIColor redColor] range:range8];// 图文混排 支持各种格式包括gifYYImage *image = [YYImage imageNamed:@"house1"];image.preloadAllAnimatedImageFrames = YES;YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:image];NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:imageView contentMode:UIViewContentModeTop attachmentSize:imageView.size alignToFont:[UIFont systemFontOfSize:18] alignment:YYTextVerticalAlignmentCenter];// [attriStr appendAttributedString:attachText];[attriStr insertAttributedString:attachText atIndex:range8.location];//Gif图片NSString *  path = [[NSBundle mainBundle] pathForScaledResource:@"gif_loading" ofType:@"gif"];NSData *data = [NSData dataWithContentsOfFile:path];//修改表情大小YYImage *image2 = [YYImage imageWithData:data scale:2];image2.preloadAllAnimatedImageFrames = YES;YYAnimatedImageView *imageView2 = [[YYAnimatedImageView alloc] initWithImage:image2];NSMutableAttributedString *attachText2 = [NSMutableAttributedString attachmentStringWithContent:imageView2 contentMode:UIViewContentModeCenter attachmentSize:imageView2.size alignToFont:[UIFont systemFontOfSize:18] alignment:YYTextVerticalAlignmentCenter];[attriStr appendAttributedString:attachText2];label.attributedText = attriStr;// 创建容器YYTextContainer *container = [[YYTextContainer alloc] init];//限制宽度container.size = CGSizeMake(300, CGFLOAT_MAX);//根据容器和文本创建布局对象YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:attriStr];//得到文本高度CGFloat titleLabelHeight = layout.textBoundingSize.height;//设置framelabel.frame = CGRectMake(20,84,300,titleLabelHeight);//此处的YYTextLayout可以计算富文本的高度,他有一个属性textBoundingRect和textBoundingSize,container.size是用来限制宽度的,可以计算高度//YYTextLayout是用来赋值给YYLabel,相当于UILabel的attributedText//如果单纯的做点击处理可以用attributedText直接赋值给YYLabel,但是如果需要异步渲染就必须用YYTextLayout[self.view addSubview:label];

YYModel — 高性能的 iOS JSON 模型框架
YYCache — 高性能的 iOS 缓存框架。
YYImage — 功能强大的 iOS 图像框架。
YYWebImage — 高性能的 iOS 异步图像加载框架。
YYText — 功能强大的 iOS 富文本框架。
YYKeyboardManager — iOS 键盘监听管理工具。
YYDispatchQueuePool — iOS 全局并发队列管理工具。
YYAsyncLayer — iOS 异步绘制与显示的工具。
YYCategories — 功能丰富的 Category 类型工具库。

YYKit 学习笔记之 YYLabel相关推荐

  1. PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 call

    您的位置 首页 PyTorch 学习笔记系列 PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 发布: 2017年8月4日 7,195阅读 ...

  2. 容器云原生DevOps学习笔记——第三期:从零搭建CI/CD系统标准化交付流程

    暑期实习期间,所在的技术中台-效能研发团队规划设计并结合公司开源协同实现符合DevOps理念的研发工具平台,实现研发过程自动化.标准化: 实习期间对DevOps的理解一直懵懵懂懂,最近观看了阿里专家带 ...

  3. 容器云原生DevOps学习笔记——第二期:如何快速高质量的应用容器化迁移

    暑期实习期间,所在的技术中台-效能研发团队规划设计并结合公司开源协同实现符合DevOps理念的研发工具平台,实现研发过程自动化.标准化: 实习期间对DevOps的理解一直懵懵懂懂,最近观看了阿里专家带 ...

  4. 2020年Yann Lecun深度学习笔记(下)

    2020年Yann Lecun深度学习笔记(下)

  5. 2020年Yann Lecun深度学习笔记(上)

    2020年Yann Lecun深度学习笔记(上)

  6. 知识图谱学习笔记(1)

    知识图谱学习笔记第一部分,包含RDF介绍,以及Jena RDF API使用 知识图谱的基石:RDF RDF(Resource Description Framework),即资源描述框架,其本质是一个 ...

  7. 计算机基础知识第十讲,计算机文化基础(第十讲)学习笔记

    计算机文化基础(第十讲)学习笔记 采样和量化PictureElement Pixel(像素)(链接: 采样的实质就是要用多少点(这个点我们叫像素)来描述一张图像,比如,一幅420x570的图像,就表示 ...

  8. Go 学习推荐 —(Go by example 中文版、Go 构建 Web 应用、Go 学习笔记、Golang常见错误、Go 语言四十二章经、Go 语言高级编程)

    Go by example 中文版 Go 构建 Web 应用 Go 学习笔记:无痕 Go 标准库中文文档 Golang开发新手常犯的50个错误 50 Shades of Go: Traps, Gotc ...

  9. MongoDB学习笔记(入门)

    MongoDB学习笔记(入门) 一.文档的注意事项: 1.  键值对是有序的,如:{ "name" : "stephen", "genda" ...

  10. NuGet学习笔记(3) 搭建属于自己的NuGet服务器

    文章导读 创建NuGetServer Web站点 发布站点到IIS 添加本地站点到包包数据源 在上一篇NuGet学习笔记(2) 使用图形化界面打包自己的类库 中讲解了如何打包自己的类库,接下来进行最重 ...

最新文章

  1. 人脸服务器如何与门禁系统对接,人脸识别门禁系统终端设备接口说明
  2. 高斯混合模型理解汇总
  3. 报名 | 瓜子二手车周洲:如何玩转AI赋能下的新零售?
  4. c语言如何判断数据是否符合正态分布_如何判断机器学习数据集是否是线性的?...
  5. 【转】wordpress/wp-includes目录文件概述
  6. linux c 读取摄像头,Linux下onvif客户端获取ipc摄像头 获取能力:GetCapabilities
  7. 学习的回顾--数组的有关内容
  8. window服务器上搭建git服务,window server git!!!
  9. 用女朋友动态图做微信二维码,小白都会
  10. Spring Security 用户登录实战
  11. 送6个Gmail邀请!
  12. mysql 事务操作入门
  13. Debian安装autoconf
  14. s3c2410_gpio_setpin()等系列函数
  15. 设置android模拟器的ip地址,设置Android模拟器IP地址
  16. 解密搭建平台赚钱的方法一:详解搭建网站收入的几个来源
  17. 小米深圳通服务器维护中,小米已开通深圳通功能 换手机还能退钱移卡
  18. vi命令下编辑文件时,按insert键文件底部不出现“INSERT”问题
  19. https证书过期时间应该怎么处理
  20. EV代码签名证书可以自助续签吗?

热门文章

  1. LCD 12864B V2.0的使用
  2. 常用の工具(update 22.11.11)
  3. 微型计算机控制技术第二版答案第四章,微型计算机控制技术答案第四章2.pdf
  4. JAVA开发的人力资源管理系统
  5. bat调用vbs脚本
  6. Java 移位运算符的复合_Java移位运算符
  7. 最全的Windows进程详解!
  8. jQuery超酷轻量级响应式lightbox插件
  9. SQL Server各版本官方下载地址
  10. 项目的三种组织结构形式分析与比较