在网上找到的大部分都是横向的走马灯效果,就自己动手谢了一个上下滚动的。说的准确一点的话可能不算走马灯,文本是有停留的,每次显示一条。不停留连续的走马灯效果正在研究,后期补上。
TableViewCell调用

        NSArray * arr = @[@"qwer",@"12345",@"asdfg",@"54321",@"zxcvb",@"09877",@"567889"];dynamicMessageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:shoppersCell];if (cell == nil) {cell = [[dynamicMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:shoppersCell dataArray:arr];}return cell;

Cell

#import "BTableViewCell.h"@interface dynamicMessageTableViewCell : BTableViewCell-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier dataArray:(NSArray *)titleArray;
//-(void)info:(NSArray *)titleArray;@end

BBCyclingLabel

#import "dynamicMessageTableViewCell.h"
#import "BBCyclingLabel.h"@interface dynamicMessageTableViewCell()
{BBCyclingLabel * _bbCyclingLable;NSArray * _titleArr;UITextField * _text;int a;int _msgCount;}@end@implementation dynamicMessageTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier dataArray:(NSArray *)titleArray
{if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {_text = [[UITextField alloc] initWithFrame:CGRectMake(80, 0, SCREEN_WIDTH-80, 30)];_titleArr = [[NSArray alloc] init];_titleArr = titleArray;UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 50, 50)];[imagev setImage:GetImage(@"icon_notice.png")];[self addSubview:imagev];[self createUI];}return self;
}-(void)createUI
{_bbCyclingLable  = [[BBCyclingLabel alloc]initWithFrame:CGRectMake(80, 0, SCREEN_WIDTH-80, 30) andTransitionType:BBCyclingLabelTransitionEffectScrollUp];//    [_text addSubview:_bbCyclingLable];
//    _text.borderStyle = UITextBorderStyleRoundedRect;
//    [self addSubview:_text];[self addSubview:_bbCyclingLable];NSTimer *time = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(change) userInfo:nil repeats:YES];[time fire];a = 0;
}-(void)info:(NSArray *)titleArray
{_titleArr = titleArray;
}//数组中的内容仅供测试用,具体内容可以通过后台服务器获取或者写死(数据条数可以改变,我写的是3条)
-(void)change
{a++;if (0<=a && a<_titleArr.count) {_bbCyclingLable.text = [_titleArr objectAtIndex:a];}else{a=0;_bbCyclingLable.text = [_titleArr objectAtIndex:a];}
}
//
// Copyright 2012 BiasedBit
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
////
//  Created by Bruno de Carvalho -- @biasedbit / http://biasedbit.com
//  Copyright (c) 2012 BiasedBit. All rights reserved.
//#pragma mark - Enumstypedef enum
{// User must provide pre-transition and transition blocksBBCyclingLabelTransitionEffectCustom = 0,BBCyclingLabelTransitionEffectFadeIn    = 1 << 0,BBCyclingLabelTransitionEffectFadeOut   = 1 << 1,BBCyclingLabelTransitionEffectCrossFade = BBCyclingLabelTransitionEffectFadeIn |BBCyclingLabelTransitionEffectFadeOut,BBCyclingLabelTransitionEffectZoomIn  = 1 << 2,BBCyclingLabelTransitionEffectZoomOut = 1 << 3,BBCyclingLabelTransitionEffectScaleFadeOut = BBCyclingLabelTransitionEffectFadeIn |BBCyclingLabelTransitionEffectFadeOut |BBCyclingLabelTransitionEffectZoomOut,BBCyclingLabelTransitionEffectScaleFadeIn  = BBCyclingLabelTransitionEffectFadeIn |BBCyclingLabelTransitionEffectFadeOut |BBCyclingLabelTransitionEffectZoomIn,// These two move the entering label from above/below to center and exiting label up/down without cross-fade// It's a good idea to set the clipsToBounds property of the BBCyclingLabel to true and use this in a confined spaceBBCyclingLabelTransitionEffectScrollUp   = 1 << 4,BBCyclingLabelTransitionEffectScrollDown = 1 << 5,BBCyclingLabelTransitionEffectDefault = BBCyclingLabelTransitionEffectCrossFade
} BBCyclingLabelTransitionEffect;#pragma mark - Custom typestypedef void(^BBCyclingLabelPreTransitionBlock)(UILabel* labelToEnter);
typedef void(^BBCyclingLabelTransitionBlock)(UILabel* labelToExit, UILabel* labelToEnter);#pragma mark -@interface BBCyclingLabel : UIView#pragma mark Public properties@property(assign, nonatomic) BBCyclingLabelTransitionEffect   transitionEffect;
@property(copy,   nonatomic) BBCyclingLabelPreTransitionBlock preTransitionBlock;
@property(copy,   nonatomic) BBCyclingLabelTransitionBlock    transitionBlock;
@property(assign, nonatomic) NSTimeInterval                   transitionDuration;
// Same properties as UILabel, these will be propagated to the underlying labels
@property(copy,   nonatomic) NSString*            text;
@property(strong, nonatomic) UIFont*              font;
@property(strong, nonatomic) UIColor*             textColor;
@property(strong, nonatomic) UIColor*             shadowColor;
@property(assign, nonatomic) CGSize               shadowOffset;
@property(assign, nonatomic) UITextAlignment      textAlignment;
@property(assign, nonatomic) UILineBreakMode      lineBreakMode;
@property(assign, nonatomic) NSInteger            numberOfLines;
@property(assign, nonatomic) BOOL                 adjustsFontSizeToFitWidth;
@property(assign, nonatomic) CGFloat              minimumFontSize;
@property(assign, nonatomic) UIBaselineAdjustment baselineAdjustment;#pragma mark Creation- (id)initWithFrame:(CGRect)frame andTransitionType:(BBCyclingLabelTransitionEffect)transitionEffect;#pragma mark Public methods/*! Sets the text for the next label and performs a transition between current and next label (if animated is YES) */
- (void)setText:(NSString*)text animated:(BOOL)animated;@end
//
// Copyright 2012 BiasedBit
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
////
//  Created by Bruno de Carvalho -- @biasedbit / http://biasedbit.com
//  Copyright (c) 2012 BiasedBit. All rights reserved.
//#import "BBCyclingLabel.h"#pragma mark - ConstantsNSTimeInterval const kBBCyclingLabelDefaultTransitionDuration = 0.3;#pragma mark -@interface BBCyclingLabel ()
{NSUInteger _currentLabelIndex;
}#pragma mark Private properties@property(strong, nonatomic) NSArray* labels;
@property(strong, nonatomic) UILabel* currentLabel;#pragma mark Private helpers- (void)setupWithEffect:(BBCyclingLabelTransitionEffect)effect andDuration:(NSTimeInterval)duration;
- (void)prepareTransitionBlocks;
- (NSUInteger)nextLabelIndex;
- (void)resetLabel:(UILabel*)label;@end#pragma mark -@implementation BBCyclingLabel#pragma mark Property synthesizers@synthesize transitionEffect   = _transitionEffect;
@synthesize preTransitionBlock = _preTransitionBlock;
@synthesize transitionBlock    = _transitionBlock;
@synthesize transitionDuration = _transitionDuration;
// Private
@synthesize labels       = _labels;
@synthesize currentLabel = _currentLabel;#pragma mark Creation- (id)initWithFrame:(CGRect)frame
{self = [super initWithFrame:frame];if (self != nil) {[self setupWithEffect:BBCyclingLabelTransitionEffectDefaultandDuration:kBBCyclingLabelDefaultTransitionDuration];}return self;
}- (id)initWithCoder:(NSCoder*)coder
{self = [super initWithCoder:coder];if (self != nil) {[self setupWithEffect:BBCyclingLabelTransitionEffectDefaultandDuration:kBBCyclingLabelDefaultTransitionDuration];}return self;
}- (id)initWithFrame:(CGRect)frame andTransitionType:(BBCyclingLabelTransitionEffect)transitionEffect;
{self = [super initWithFrame:frame];if (self != nil) {[self setupWithEffect:transitionEffectandDuration:kBBCyclingLabelDefaultTransitionDuration];}return self;
}#pragma mark Manual property accessors- (void)setTransitionEffect:(BBCyclingLabelTransitionEffect)transitionEffect
{_transitionEffect = transitionEffect;[self prepareTransitionBlocks];
}- (NSString*)text
{return _currentLabel.text;
}- (void)setText:(NSString*)text
{[self setText:text animated:YES];
}- (UIFont*)font
{return _currentLabel.font;
}- (void)setFont:(UIFont*)font
{for (UILabel* label in _labels) {label.font = font;}
}- (UIColor*)textColor
{return _currentLabel.textColor;
}- (void)setTextColor:(UIColor*)textColor
{for (UILabel* label in _labels) {label.textColor = textColor;}
}- (UIColor*)shadowColor
{return _currentLabel.shadowColor;
}- (void)setShadowColor:(UIColor*)shadowColor
{for (UILabel* label in _labels) {label.shadowColor = shadowColor;}
}- (CGSize)shadowOffset
{return _currentLabel.shadowOffset;
}- (void)setShadowOffset:(CGSize)shadowOffset
{for (UILabel* label in _labels) {label.shadowOffset = shadowOffset;}
}- (UITextAlignment)textAlignment
{return _currentLabel.textAlignment;
}- (void)setTextAlignment:(UITextAlignment)textAlignment
{for (UILabel* label in _labels) {label.textAlignment = textAlignment;}
}- (UILineBreakMode)lineBreakMode
{return _currentLabel.lineBreakMode;
}- (void)setLineBreakMode:(UILineBreakMode)lineBreakMode
{for (UILabel* label in _labels) {label.lineBreakMode = lineBreakMode;}
}- (NSInteger)numberOfLines
{return _currentLabel.numberOfLines;
}- (void)setNumberOfLines:(NSInteger)numberOfLines
{for (UILabel* label in _labels) {label.numberOfLines = numberOfLines;}
}- (BOOL)adjustsFontSizeToFitWidth
{return _currentLabel.adjustsFontSizeToFitWidth;
}- (void)setAdjustsFontSizeToFitWidth:(BOOL)adjustsFontSizeToFitWidth
{for (UILabel* label in _labels) {label.adjustsFontSizeToFitWidth = adjustsFontSizeToFitWidth;}
}- (CGFloat)minimumFontSize
{return _currentLabel.minimumFontSize;
}- (void)setMinimumFontSize:(CGFloat)minimumFontSize
{for (UILabel* label in _labels) {label.minimumFontSize = minimumFontSize;}
}- (UIBaselineAdjustment)baselineAdjustment
{return _currentLabel.baselineAdjustment;
}- (void)setBaselineAdjustment:(UIBaselineAdjustment)baselineAdjustment
{for (UILabel* label in _labels) {label.baselineAdjustment = baselineAdjustment;}
}#pragma mark Public methods- (void)setText:(NSString*)text animated:(BOOL)animated
{NSUInteger nextLabelIndex = [self nextLabelIndex];UILabel* nextLabel = [_labels objectAtIndex:nextLabelIndex];UILabel* previousLabel = _currentLabel;nextLabel.text = text;// Resetting the label state ensures we can change the transition type without extra code on pre-transition block.// Without it a transition that has no alpha changes would have to ensure alpha = 1 on pre-transition block (as// well as with every other possible animatable property)[self resetLabel:nextLabel];// Update both current label index and current label pointerself.currentLabel = nextLabel;_currentLabelIndex = nextLabelIndex;// Prepare the next label before the transition animationif (_preTransitionBlock != nil) {_preTransitionBlock(nextLabel);} else {// If no pre-transition block is set, prepare the next label for a cross-fadenextLabel.alpha = 0;}// Unhide the label that's about to be shownnextLabel.hidden = NO;void (^changeBlock)() = ^() {// Perform the user provided changesif (_transitionBlock != nil) {_transitionBlock(previousLabel, nextLabel);} else {// If no transition block is set, perform a simple cross-fadepreviousLabel.alpha = 0;nextLabel.alpha = 1;}};void (^completionBlock)(BOOL) = ^(BOOL finished) {if (finished) {// TODO this is kind of bugged since all transitions that include affine transforms always return finished// as true, even when it doesn't finish...previousLabel.hidden = YES;}};if (animated) {// Animate the transition between both labels[UIView animateWithDuration:_transitionDuration animations:changeBlock completion:completionBlock];} else {changeBlock();completionBlock(YES);}
}#pragma mark Private helpers- (void)setupWithEffect:(BBCyclingLabelTransitionEffect)effect andDuration:(NSTimeInterval)duration
{NSUInteger size = 2;NSMutableArray* labels = [NSMutableArray arrayWithCapacity:size];for (NSUInteger i = 0; i < size; i++) {UILabel* label = [[UILabel alloc] initWithFrame:self.bounds];[self addSubview:label];label.backgroundColor = [UIColor clearColor];label.hidden = YES;label.numberOfLines = 0;[labels addObject:label];}_currentLabelIndex = 0;self.currentLabel = [labels objectAtIndex:0];self.labels = labels;_currentLabel.hidden = NO;self.transitionEffect = effect;self.transitionDuration = duration;
}- (void)prepareTransitionBlocks
{//if matches customif (_transitionEffect == BBCyclingLabelTransitionEffectCustom) {return;}BBCyclingLabelTransitionEffect type = _transitionEffect;self.preTransitionBlock = ^(UILabel* labelToEnter) {if (type & BBCyclingLabelTransitionEffectFadeIn) {labelToEnter.alpha = 0;}if (type & BBCyclingLabelTransitionEffectZoomIn) {labelToEnter.transform = CGAffineTransformMakeScale(0.5, 0.5);}if (type & (BBCyclingLabelTransitionEffectScrollUp | BBCyclingLabelTransitionEffectScrollDown)) {CGRect frame = labelToEnter.frame;if (type & BBCyclingLabelTransitionEffectScrollUp) {frame.origin.y = self.bounds.size.height;}if (type & BBCyclingLabelTransitionEffectScrollDown) {frame.origin.y = 0 - frame.size.height;}labelToEnter.frame = frame;}};self.transitionBlock = ^(UILabel* labelToExit, UILabel* labelToEnter) {if (type & BBCyclingLabelTransitionEffectFadeIn) {labelToEnter.alpha = 1;}if (type & BBCyclingLabelTransitionEffectFadeOut) {labelToExit.alpha = 0;}if (type & BBCyclingLabelTransitionEffectZoomOut) {labelToExit.transform = CGAffineTransformMakeScale(1.5, 1.5);}if (type & BBCyclingLabelTransitionEffectZoomIn) {labelToEnter.transform = CGAffineTransformIdentity;}if (type & (BBCyclingLabelTransitionEffectScrollUp | BBCyclingLabelTransitionEffectScrollDown)) {CGRect frame = labelToExit.frame;CGRect enterFrame = labelToEnter.frame;if (type & BBCyclingLabelTransitionEffectScrollUp) {frame.origin.y = 0 - frame.size.height; enterFrame.origin.y = roundf((self.bounds.size.height / 2) - (enterFrame.size.height / 2));}if (type & BBCyclingLabelTransitionEffectScrollDown) {frame.origin.y = self.bounds.size.height;enterFrame.origin.y = roundf((self.bounds.size.height / 2) - (enterFrame.size.height / 2));}labelToExit.frame = frame;labelToEnter.frame = enterFrame;}};
}- (NSUInteger)nextLabelIndex
{return (_currentLabelIndex + 1) % [_labels count];
}- (void)resetLabel:(UILabel*)label
{label.alpha = 1;label.transform = CGAffineTransformIdentity;label.frame = self.bounds;
}@end

iOS走马灯上下滚动显示文本相关推荐

  1. java 滚动显示信息_滚动显示文本的Java程序

    /** * 文件名:ScrollFrame.java * 环境: GNU/Linux Ubuntu 7.04 + Eclipse 3.2 + JDK 1.6 * 功能:滚动文本显示面板Demo * 版 ...

  2. ipad html 禁止放大镜,IOs Cordova长按显示文本选择放大镜即使禁用文本选择,如何删除?...

    我有一个非常奇怪的问题.在我的iOS上的cordova应用程序,当我长时间在应用程序的任何地方,我会收到一个弹出的文本选择放大镜. 例: 顶部的气泡被锁定在屏幕的顶部,当我的手指从一侧移到另一边时,按 ...

  3. MFC开发之静态文本框实现编辑框滚动显示文字效果

    效果: 1.通过滚轮拖动进行滚动显示 2.通过鼠标滚轮显示 3.保证滚动每行和字实际高度一致 4.滚轮行数和需要滚动的字行数一致 正文:需要自绘静态文本框 一.使用滚轮和滚动条 在PreTransla ...

  4. 前端教程分享:十行代码实现title滚动显示

    细心的同学可能会发现我们网站的title显示的文字永远都是固定的不会移动的,那么有没有什么办法能让title滚动显示呢? 怎么样才能实现网页标题滚动效果呢?时间就是金钱,废话不多说,直接上代码: 然后 ...

  5. 解决alert在ios版微信中显示url的问题(重写alert)

    为了解决alert在ios版微信中显示url的问题 window.alert = function(name){var iframe = document.createElement("IF ...

  6. php中滚动显示文字,HTML如何实现文字的滚动效果

    在HTML中,可以通过HTML的标签来实现文字的滚动效果,通过设置标签里的不同属性来实现不同的文字的滚动效果. 在HTML中实现文字的滚动效果其实很简单,本篇文章就给大家介绍HTML 标签实现文字的滚 ...

  7. 基于MapWinGis的开发探索(三)--改善缩放、渲染、显示文本

    继续对MapWinGis进行研究探索,紧接上一篇文章.MapWinGis自身有很多功能,此篇主要也是基于其内在方法来写的.除了第二点显示文本是根据其源代码进行扩展的. 原图: 一.改善缩放功能 上一版 ...

  8. ant 走马灯面板指示显示不出来_触摸屏报警信息显示设置方法

    人机界面(HMI)是自动化设备中非常常用的器件,用于替代操作面板上的实体按钮或者显示指示.人机界面的适用极大的减小了设备操作面板的尺寸,提升了设备的整体美观度.随着自动化设备的自动化程度的提高,也对设 ...

  9. 在界面中显示文本内容

    iOS有单行和多行显示文本的控件对象: UITextField:简单的单行 UITextView:可滚屏的多行 在这里使用的是多行文本,即UITextView. 代码很简单,需要声明该视图的位置,字体 ...

最新文章

  1. 我在ChinaUnix上看到的有点点用的帖子
  2. RocketMQ Summit 2022 案例征集中
  3. Columns Controller
  4. 【Python】line.strip().split(‘,‘)含义
  5. java怎么申请变量_java怎么声明变量
  6. EasyUi – 1.入门
  7. 【新华网】阿里与重庆9所高校合作 加快大数据人才培养
  8. 装机——2021年底装机推荐,附9000元DIY介绍
  9. 计算机cad知识,计算机与Cad制图知识点.doc
  10. 卸载掉WPS后安装Office文档图标显示异常
  11. 用max的角度来解析blender建模!
  12. 灵敏度分享码显示服务器不可用,和平精英灵敏度分享码怎么使用 复制高玩主播灵敏度方法...
  13. 怎样利用计算机电源,计算机电源功耗如何计算?如何使用电脑功率计算器?
  14. 利用Python(pyserial、minimalmodbus、modbus_tk)进行单片机通信
  15. 2惠普暗影精灵恢复出厂设置
  16. JavaScript案例之电影院电子选票
  17. 组合数(字典序排列)
  18. python列表元组字典集合实验心得_python学习小总结(列表、元组、字典、集合、字符串)...
  19. 智能可穿戴的时尚单品,到底是不是“智商税”?
  20. 2022金三银四前端面试题预告

热门文章

  1. Android kotlin 代码设置短信指定SIM卡发送
  2. 【V影视】超级Nice的一款电视盒子,更新快,画质好,剧多,免费
  3. 在新浪博客上挂ggad,赚美元
  4. 台达DVP系列PLC与欧姆龙E5CZ温控器485通讯
  5. 设计一个汽车类Auto,其中包含一个表示速度的double型成员变量speed和表示启动的start0方法、表示加速的speedUp()方法以及表示停止的stop()方法。
  6. 推荐一款在IDEA里使用的AI辅助工具-Bito
  7. 聚焦降本增效,用户满意度成达内教育增长“晴雨表”
  8. dism 分割镜像_使用Dism命令对Win7镜像进行操作
  9. 用二维数组写杨辉三角
  10. 领英工具-领英精灵免费使用方法