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