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. 枚举 ---- B. RPG Protagonist[Educational Codeforces Round 94 (Rated for Div. 2)]数学枚举
  2. Java8 HashMap源码分析
  3. 2.2.2 物理层设备(中继器、集线器)
  4. python字符串成熟编码_python字符串转公式两种方法获取网页编码python版
  5. 选择、插入、冒泡排序
  6. 表格占据整个页面_excel转换为pdf6个示例,在多个工作表、表格和空白页中进行选择...
  7. h5海报设计开源工具_5个用于教幼儿阅读的开源工具
  8. java中53个关键字的意义及使用方法
  9. linux远程连接交换机,思科:路由器、交换机 ssh远程连接
  10. Hyperledger Fabric教程(1)--Hyperledger Fabric 老版本 1.1.0 快速部署安装
  11. 优秀的博客地址-冰冻三尺非一日之寒
  12. H. Zebras and Ocelots -ICPC North Central NA Contest 2017
  13. opencv-11-中值滤波及自适应中值滤波
  14. 历年苹果秋季发布会产品
  15. Arthas、jprofiler使用
  16. 互联网让FBI走下神坛
  17. oracle物料属性主要单位,Oracle EBS物料属性设定.doc
  18. 浏览器打不开网页(电脑有网)
  19. 吉德林法则 (Kidlin's Law)的真实案例(1)
  20. 【软件测试-实验-7】使用LR进行性能测试

热门文章

  1. 八大主流浏览器自动填表功能大比拼
  2. 【转】让你的手机成为你的电脑摄像头
  3. 安卓手机上超好用的4款C语言IDE(附下载地址)
  4. ​香农与信息论三大定律
  5. 格式化日期为xxxx-xx-xx hh:mm:ss
  6. Real Estate Photography: Exterior at Twilight 房地产摄影:暮光之城 Lynda课程中文字幕
  7. html flsh 特效,FLASH教程:开花的特效Flash实例
  8. window防火墙端口映射_Windows 防火墙上也有端口映射功能
  9. WindowsXP系统主题成Windows7风格windowsxp主题包
  10. 计算机图形学——大作业