实现在有限的label上动态的显示所有文字
来源:互联网 发布:math js w3c 编辑:程序博客网 时间:2024/06/06 16:35
sds
github连接https://github.com/yuchuanfeng/CFDynamicLabel
思路
1创建一个view 作为所有内容的父控件, 并且添加到上面一个 label, 作为显示文字的载体
UILabel* contentLabel = [[UILabel alloc] init];[contentLabel sizeToFit];contentLabel.backgroundColor = [UIColor clearColor]; _contentLabel = contentLabel; [self addSubview:self.contentLabel];
2给内容view的layer添加一个mask层, 并且设置其范围为整个view的bounds, 这样就让超出view的内容不会显示出来
CAShapeLayer* maskLayer = [CAShapeLayer layer];maskLayer.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;self.layer.mask = maskLayer;
3给label添加动画
CAKeyframeAnimation* keyFrame = [CAKeyframeAnimation animation];keyFrame.keyPath = @"transform.translation.x";keyFrame.values = @[@(0), @(-space), @(0)];keyFrame.repeatCount = NSIntegerMax;keyFrame.duration = self.speed * self.contentLabel.text.length;keyFrame.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithControlPoints:0 :0 :0.5 :0.5]];keyFrame.delegate = self;[self.contentLabel.layer addAnimation:keyFrame forKey:nil];
// 创建CFDynamicLabel* testLabel = [[CFDynamicLabel alloc] initWithFrame:CGRectMake(100, 300, 180, 21)];// 设置滚动速度testLabel.speed = 0.6;[self.view addSubview:testLabel];// 设置基本属性testLabel.text = @"我不想说再见,不说再见,越长大越孤单";testLabel.textColor = [UIColor yellowColor];testLabel.font = [UIFont systemFontOfSize:23];testLabel.backgroundColor = [UIColor grayColor];
0 0
- 实现在有限的label上动态的显示所有文字
- 一个label上的文字显示不同的颜色
- Java应用小技巧---label上的文字显示下划线
- label显示不同颜色的文字
- 实现自定义label上 指定文字的颜色
- 在图片上动态的写文字
- Label显示不同颜色、字体的文字
- Label显示不同颜色、字体的文字
- 根据Label的文字内容动态计算Label高度
- 在label控件上动态的添加图片
- 一个带有属性的字符串(比如文字颜色/字体属性等文字属性) 在label上显示需要使用 attributedText 属性
- ios 调整Label上文字的行距
- label上的文字加上划线
- Swift UIPasteboard 复制label上的文字
- RFSegmentView在iOS7设备上不显示label的解决方案
- 在同一个label上显示 两种规格的字体
- 如何在QT的label上显示图像
- 如何设置在一个Label上显示不同颜色的text
- POJ 3419Difference Is Beautiful
- 网易16年研发实习生笔试题 - 比较重量
- get与post的区别get请求方式与post请求方式的区别
- MAC下清理工具Omnidisksweeper
- Java将多个文件压缩为一个文件
- 实现在有限的label上动态的显示所有文字
- Swiper常用于移动端网站的内容触摸滑动
- 客户端与服务器交互---http协议
- hud1233还是畅通工程并 最小生成树 Prim算法
- Makefile快速学习
- Hadoop2.7.0学习——完全分布式搭建
- oracle 11R2 ADG LGWR: Error 16086 opening RFS destination for reconnect
- node.js中Socket.IO的进阶使用技巧
- java数据连接池的几种区别和使用