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标签+左右箭头实现来回滚动文章,引入项目后,我们的组长说样子太丑了,小颖觉得还好啊,要不大家评评理,看下丑不丑?无图无真相,来上图: 看吧其 ...
随机推荐
- DOS/BAT批处理if exist else 语句的几种用法
在DOS批处理命令中常常会通过if语句来进行判断来执行下面的命令, 那么批处理if语句怎么用呢,下面学无忧小编就来说说有关批处理if以及if exist else语句的相关内容.一.批处理if书写格式 ...
- C++ 单词接龙
问题描述: 拉姆刚刚开始学习英文字母,对单词排序很感兴趣,他能够迅速确定是否可以将这些单词排列在一个列表中,使得该列表中任何单词的首字母与前一个单词的尾字母相同,力能编写一个计算机程序帮助拉姆进行判断 ...
- oracle查看被锁的表以及解锁表
在oracle 上面查看别锁定的表,以及解锁表的sql: select t3.object_name,t3.owner,t2.machine,t2.sid,t2.serial# from v$lock ...
- 从0开始 图论学习 邻接表 STL vector
邻接表表示 用vector实现 writer:pprp 代码如下: #include <bits/stdc++.h> using namespace std; const int maxn ...
- Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
一.linux中配置redis,使用java连接测试时报错: Exception in thread "main" redis.clients.jedis.exceptions.J ...
- pyspider—爬取下载图片
以第一ppt网站为例:http://www.1ppt.com/ from pyspider.libs.base_handler import * import urllib2,HTMLParser,r ...
- java自带的MD5
前言: MD5可生成16.32.64位数的签名. // MD5加码,32位 public static String toMD5(String plainText) { String r ...
- Nordic老版官网介绍(2018-11-30停止更新)
1. Nordic官网及资料下载 Nordic官网主页:https://www.nordicsemi.com/,进入官网后,一般点击“Products”标签页,即进入Nordic产品下载首页,其独立链 ...
- SpringBoot学习(2)
三.日志 1.日志框架 springboot:底层是spring框架,spring框架默认使用JCL; springboot选用SLF4j和logback; 2.SLF4j使用 1.如何在系统中使用S ...
- Unity使用Win10语音
1. 引入头文件 using UnityEngine.Windows.Speech; 2. 设置识别词 public string[] keywords = new string[] { ...