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标签+左右箭头实现来回滚动文章,引入项目后,我们的组长说样子太丑了,小颖觉得还好啊,要不大家评评理,看下丑不丑?无图无真相,来上图: 看吧其 ...
随机推荐
- getJson同步
$.ajaxSettings.async = false;//在执行之前加$.ajaxSettings.async = false; (同步执行) function get_no_order_ar ...
- 【前端】用javaScript实现实现一个球池的效果
ballPool 用javaScript实现实现一个球池的效果,实现效果如下所示: 动图: 截图: HTML代码: <!DOCTYPE html> <html > <he ...
- iPhone Screen FAQ
Q: Why is it a blank window after openning the app and connect mobile device? A: Please make sure th ...
- JSON 中JsonConfig的使用(转)
我们通常对一个Json串和Java对象进行互转时,经常会有选择性的过滤掉一些属性值,而json-lib包中的JsonConfig为我们提供了这种 功能,具体实现方法有以下几种.(1)建立JsonCon ...
- JDK 中的监控与故障处理工具-05 (jstack)
jstack : stack trace for java jstack 命令用于生成虚拟机当前时刻的线程快照 (threaddump).线程快照是当前虚拟机中每一条线程正在执行的方法堆栈的集合,生成 ...
- 贯众云平台脚本编写之判断、循环以及shell命令的使用
最近使用贯众云平台工具写脚本,进行Ui界面的自动化测试.刚开始接触,确实碰到不少的问题,稍微难点的就是判断语句,循环语句以及shell命令的使用,尤其是对于咱们测试这样比较少接触代码的人来说. 其实吧 ...
- PHP 重载方法 __call()
__call() 方法用于监视错误的方法调用. __call()(Method overloading) 为了避免当调用的方法不存在时产生错误,可以使用 __call() 方法来避免.该方法在调用的方 ...
- maven笔记(2)
项目管理利器(Maven)——maven的生命周期和插件Maven的生命周期大概如下:clean compile test package install这几个命令对应了一个项目的完整的构建过程,这几 ...
- Redis-CentOS7安装
安装 Redis是c语言开发的. 安装redis需要c语言的编译环境.如果没有gcc需要在线安装.yum install gcc-c++ 安装步骤: 第一步:redis的源码包上传到linux系统. ...
- uva10002凸包重心
把每个三角形看成一个质点,坐标就是各自的重心, #include<map> #include<set> #include<cmath> #include<qu ...