ios Label TextFile 文本来回滚动 包括好用的三方
通常显示不够了,比如八个字。只能显示6个字 。产品要求 来回滚动
下面有两种 方法 : 一种UIScrollView 一种 View动画 如果不能满足你 请点击这个 https://github.com/cbpowell/MarqueeLabel 好用的第三方
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor]; // 注册字体
REGISTER_FONT(bundleFont(@"新蒂小丸子体.ttf"), @"新蒂小丸子体"); // 获取文本
NSString *string = @" 喜欢这首情思幽幽的曲子,仿佛多么遥远,在感叹着前世的情缘,又是那么柔软,在祈愿着来世的缠绵。《莲的心事》,你似琉璃一样的晶莹,柔柔地拨动我多情的心弦。我,莲的心事,有谁知?我,莲的矜持,又有谁懂? "; // 初始化label
UILabel *label = [UILabel new];
label.text = string;
label.numberOfLines = 0;
label.textColor = [UIColor cyanColor];
label.font = [UIFont fontWithName:CUSTOM_FONT(@"新蒂小丸子体", 0)
size:20.f]; // 计算尺寸
CGSize size = [label boundingRectWithSize:CGSizeMake(0, 0)];
label.frame = (CGRect){CGPointZero, size}; // 初始化ScrollView
UIScrollView *showView = \
[[UIScrollView alloc] initWithFrame:CGRectMake(0, 90, 320, size.height)];
showView.contentSize = size;
showView.showsHorizontalScrollIndicator = NO;
[showView addSubview:label];
[self.view addSubview:showView]; // 形成边缘的遮罩
UIImageView *imageView = \
[[UIImageView alloc] initWithFrame:CGRectMake(0, 90, 320, size.height)];
imageView.image = [UIImage imageNamed:@"bg"];
[self.view addSubview:imageView]; // 动画
[UIView animateKeyframesWithDuration:10
delay:7
options:UIViewKeyframeAnimationOptionAllowUserInteraction
animations:^{
// 计算移动的距离
CGPoint point = showView.contentOffset;
point.x = size.width - 320.f;
showView.contentOffset = point;
}
completion:^(BOOL finished) { }];
} 第二种 简洁版
#import "Ridehorselight.h"
@interface Ridehorselight ()
@property (nonatomic, strong) NSTimer *timer; //定时器
@property (nonatomic, weak) UIView *viewAnima; //Label的背景
@property (nonatomic, weak) UILabel *customLabel; //Label
@end
@implementation Ridehorselight
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addClildView];
[self setTimer];
}
- (void)addClildView {
self.view.backgroundColor = [UIColor whiteColor];
CGFloat viewX = (self.view.frame.size.width-200)/2;
UIView *viewAnima = [[UIView alloc] initWithFrame:CGRectMake(viewX, 100, 200, 40)];
viewAnima.backgroundColor = [UIColor yellowColor];
self.viewAnima = viewAnima;
self.viewAnima.clipsToBounds = YES; //剪掉超出view范围部分
CGFloat customLabelY = (self.viewAnima.frame.size.height-30)/2;
UILabel *customLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.viewAnima.frame.size.width, customLabelY, 200, 30)];
customLabel.text = @"跑马灯效果,滚动文本!";
customLabel.textColor = [UIColor redColor];
self.customLabel = customLabel;
[self.view addSubview:viewAnima];
[viewAnima addSubview:customLabel];
}
- (void)setTimer {
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changePos) userInfo:nil repeats:YES];
}
- (void)changePos {
CGPoint cenPos = self.customLabel.center;
if (cenPos.x < -100) {
CGFloat distance = self.customLabel.frame.size.width/2;
self.customLabel.center = CGPointMake(self.viewAnima.frame.size.width+distance, 20);
} else {
self.customLabel.center = CGPointMake(cenPos.x-5, 20);
}
}
ios Label TextFile 文本来回滚动 包括好用的三方的更多相关文章
- WPF 超长文本的来回滚动
原文:WPF 超长文本的来回滚动 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Vblegend_2013/article/details/8362 ...
- ios label 自动计算行高详解
在OC当中自动计算行高主要调用系统的 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff } span ...
- CSS 技巧一则 -- 不定宽溢出文本适配滚动
在日常布局当中,肯定经常会遇到文本内容超过容器的情况.非常常见的一种解决方案是超出省略. 但是,有的时候,由于场景的限制,可能会出现在一些无法使用超出打点省略的方法的场景,譬如在导航栏中: 这种情况下 ...
- 初识IOS,Label控件的应用。
初识IOS,Label控件的应用. // // ViewController.m // Gua.test // // Created by 郭美男 on 16/5/31. // Copyright © ...
- Android文字跑马灯控件(文本自动滚动控件)
最近在开发一个应用,需要用到文本的跑马灯效果,图省事,在网上找,但老半天都找不到,后来自己写了一个,很简单,代码如下: import android.content.Context; import a ...
- C# textbox 滚动条 随文本输入 滚动
tb_Log.SelectionStart = tb_Log.Text.Length;//设置光标位置 tb_Log.ScrollToCaret();//随文本输入 滚动
- js实现车轮的来回滚动
最近喜欢用js做车轮的来回滚动,简单的js动画分享给大家.有什么建议记得说出来大家一起讨论哦!效果图如下: 源代码: <style> #pic1{ width:20px; height:2 ...
- javascript小例子:實現四方向文本无缝滚动效果
实现一个文本无缝滚动的效果: <!DOCTYPE html> <!--[if lt IE 7 ]> <html lang="zh-CN" class= ...
- jquery实现同时展示多个tab标签+左右箭头实现来回滚动(美化版增加删除按钮)
闲聊 前段时间小颖分享了:jquery实现同时展示多个tab标签+左右箭头实现来回滚动文章,引入项目后,我们的组长说样子太丑了,小颖觉得还好啊,要不大家评评理,看下丑不丑?无图无真相,来上图: 看吧其 ...
随机推荐
- MR案例:定制Partitioner
可以继承基类Partitioner,也可以继承默认的HashPartitioner类,覆写其中的 getPartition() 方法实现自己的分区. 需求:本例是对上一个实例的改写,需求不变 pack ...
- RabbitMQ 安装使用教程
环境 CentOS7 + Python3.5 yum -y install epel-release erlang socat cd /usr/local/src wget http://www.ra ...
- LeetCode——Nth Digit
Question Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... ...
- 【网络结构】GoogLeNet inception-v1:Going deeper with convolutions论文笔记
目录 0. 论文链接 1. 概述 2. inception 3. GoogleNet 参考链接 @ 0. 论文链接 1. 概述 GoogLeNet是谷歌团队提出的一种大体保持计算资源不变的前提下, ...
- C# DES加密,KEY和IV不同设置的写法
1.KEY和IV分别赋值 //默认密钥向量 private static byte[] Iv= { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; ...
- 缓存技术内部交流_04_Cache Aside续篇
额外参考资料: http://www.ehcache.org/documentation/3.2/expiry.html F. Cache Aside 模式的问题:缓存过期 有时我们会在上线前给缓存系 ...
- mysql数据库优化课程---16、mysql慢查询和优化表空间
mysql数据库优化课程---16.mysql慢查询和优化表空间 一.总结 一句话总结: a.慢查询的话找到存储慢查询的那个日志文件 b.优化表空间的话可以用optimize table sales; ...
- python中如何剔除字符串
问题: 过滤用户输入中前后多余的空白字符 ‘ ++++abc123--- ‘ 过滤某windows下编辑文本中的’\r’: ‘hello world \r\n’ 去掉文本中unicode组 ...
- FlexboxLayout——Android弹性布局
FlexboxLayout是一个Android平台上与CSS的 Flexible box 弹性盒子布局模块 有相似功能的库.Flexbox 是CSS 的一种布局方案,可以简单.快捷的实现复杂布局. F ...
- Java中Collection 的基本认识
集合Conllection的基本概念:1.集合的基本认识:如StringBuffer&StringBuilder是集合(存储的对象类型是String).数组.对象与其很相似,但是还有区别.2. ...