通常显示不够了,比如八个字。只能显示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 文本来回滚动 包括好用的三方的更多相关文章

  1. WPF 超长文本的来回滚动

    原文:WPF 超长文本的来回滚动 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Vblegend_2013/article/details/8362 ...

  2. ios label 自动计算行高详解

    在OC当中自动计算行高主要调用系统的 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff } span ...

  3. CSS 技巧一则 -- 不定宽溢出文本适配滚动

    在日常布局当中,肯定经常会遇到文本内容超过容器的情况.非常常见的一种解决方案是超出省略. 但是,有的时候,由于场景的限制,可能会出现在一些无法使用超出打点省略的方法的场景,譬如在导航栏中: 这种情况下 ...

  4. 初识IOS,Label控件的应用。

    初识IOS,Label控件的应用. // // ViewController.m // Gua.test // // Created by 郭美男 on 16/5/31. // Copyright © ...

  5. Android文字跑马灯控件(文本自动滚动控件)

    最近在开发一个应用,需要用到文本的跑马灯效果,图省事,在网上找,但老半天都找不到,后来自己写了一个,很简单,代码如下: import android.content.Context; import a ...

  6. C# textbox 滚动条 随文本输入 滚动

    tb_Log.SelectionStart = tb_Log.Text.Length;//设置光标位置 tb_Log.ScrollToCaret();//随文本输入 滚动

  7. js实现车轮的来回滚动

    最近喜欢用js做车轮的来回滚动,简单的js动画分享给大家.有什么建议记得说出来大家一起讨论哦!效果图如下: 源代码: <style> #pic1{ width:20px; height:2 ...

  8. javascript小例子:實現四方向文本无缝滚动效果

    实现一个文本无缝滚动的效果: <!DOCTYPE html> <!--[if lt IE 7 ]> <html lang="zh-CN" class= ...

  9. jquery实现同时展示多个tab标签+左右箭头实现来回滚动(美化版增加删除按钮)

    闲聊 前段时间小颖分享了:jquery实现同时展示多个tab标签+左右箭头实现来回滚动文章,引入项目后,我们的组长说样子太丑了,小颖觉得还好啊,要不大家评评理,看下丑不丑?无图无真相,来上图: 看吧其 ...

随机推荐

  1. 一文弄懂神经网络中的反向传播法——BackPropagation【转】

    本文转载自:https://www.cnblogs.com/charlotte77/p/5629865.html 一文弄懂神经网络中的反向传播法——BackPropagation   最近在看深度学习 ...

  2. CentOS(64位)安装apr

    安装apr来提高tomcat 的可伸缩性和性能 cd /usr/local/ 1.  下载apr 和 apr-util最新版 wget http://apache.fayea.com/apache-m ...

  3. hadoop安装时报错 /usr/local/hadoop-2.6.0-stable/hadoop-2.6.0-src/hadoop-hdfs-project/hadoop-hdfs/target/findbugsXml.xml does not exist

    安装时报错:Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (site) on project ...

  4. [转载]查看JDK及Java框架的源代码

    1.点 "window"-> "Preferences" -> "Java" -> "Installed JRE ...

  5. Nordic老版官网介绍(2018-11-30停止更新)

    1. Nordic官网及资料下载 Nordic官网主页:https://www.nordicsemi.com/,进入官网后,一般点击“Products”标签页,即进入Nordic产品下载首页,其独立链 ...

  6. 【Python】@staticmethod和@classmethod的作用与区别

    前言 Python其实有3个方法,即静态方法(staticmethod),类方法(classmethod)和实例方法,一般来说,要使用某个类的方法,需要先实例化一个对象再调用方法.而使用@static ...

  7. 小米2S刷Android4.4且双系统共存

    视频教程 http://v.youku.com/v_show/id_XNjQxNzQ5NDAw.html 必备知识 进入Recovery模式:同时按住电源键+音量上键,等到屏幕亮起时,放开电源键. 特 ...

  8. 数论基础算法总结(python版)

    /* Author: wsnpyo Update Date: 2014-11-16 Algorithm: 快速幂/Fermat, Solovay_Stassen, Miller-Rabin素性检验/E ...

  9. Qt5.3中qml ApplicationWindow设置窗口无边框问题

    这个版本的qt在这里有点bug.. 设置ApplicationWindow的flags属性为Qt.FramelessWindowHint的确可以使程序无边框,但是同时程序在任务栏的图标也没了. 看文档 ...

  10. 安装使用babel-polyfill。让IE支持es6

    安装 npm install --save-dev babel-polyfill 使用 在你的代码头部加载babel-polyfill,注意一定要在你的代码开始前,第一个js文件的顶部.如果是vue在 ...