近期项目中涉及到滚动新闻通知的跑马灯效果,通过网上搜寻一些demo发现很少有上下滚动的demo,就找到一个相对来说很全面的lable文字显示的demo,就截取其中的相关文件加载到项目中(原文件类是BBCyclingLable code4App上有demo,有用到的兄弟们可以去看看,已经用过的或者有更好的实现demo的话请各位大神不吝赐教,谢谢),直接上代码(代码比较随意,仅供参考),
https://github.com/brunodecarvalho/BBCyclingLabel
http://code4app.com/ios/Cycling-Label/4fb362406803faf929000002
- (void)viedDIdload里面
{
_bbCyclingLable = [[BBCyclingLabel alloc]initWithFrame:CGRectMake(35, 0, 200, 30) andTransitionType:BBCyclingLabelTransitionEffectScrollUp];
[_text addSubview:_bbCyclingLable];
_text.borderStyle = UITextBorderStyleRoundedRect;
_text.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bottom"]];
_text.layer.cornerRadius = 20;
[bottomView addSubview:_text];
NSTimer *time = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(change) userInfo:nil repeats:YES];
[time fire];
a = 0;
}- (void)change数组中的内容仅供测试用,具体内容可以通过后台服务器获取或者写死(数据条数可以改变,我写的是3条)
{
a++;
NSArray *arrrr = [NSArray arrayWithObjects:@"wefwefwefwe",@"wewefwegfwegergrtht",@"wedwedwefwe", nil];
if ( (a-1)%3 == 0) {
_bbCyclingLable.text = [arrrr objectAtIndex:0];
}
if ( (a - 2)%3 == 0) {
_bbCyclingLable.text = [arrrr objectAtIndex:1];
}if ((a - 3)%3 == 0) {
_bbCyclingLable.text = [arrrr objectAtIndex:2];
}
}
类似下图效果,文字滚动,左边还有个小喇叭 动态更换可以使用uiimageview 自带的方法进行设置(因为就只有两张图片,来回切换)具体方法如下:(只是个例子,可以自己根据需要修改)。如果图片多的话此方法会导致内存问题,
UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
imagev.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"2"],[UIImage imageNamed:@"1"],[UIImage imageNamed:@"3"],nil];
imagev.animationDuration = 1;//时间间隔
[imagev startAnimating];
[self.view addSubview:imagev];
ps:如果大家有现成的方法实现这些功能,或者有api的话请不吝赐教,谢谢,写的不好望大家见谅!