跑马灯效果 文字上下滚动效果

近期项目中涉及到滚动新闻通知的跑马灯效果,通过网上搜寻一些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的话请不吝赐教,谢谢,写的不好望大家见谅!



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值