zoukankan      html  css  js  c++  java
  • 用UILabel实现文字滚动播放(跑马灯)效果

    - (void)viewDidLoad {
        [super viewDidLoad];
        
      //数据源
        self.messageArray = [NSArray arrayWithObjects:
                             @"1",
                             @"2",
                             @"3",
                             nil];
        self.msgCount = 0;//从第一条开始显示
    }
    -(void)viewDidAppear:(BOOL)animated {
        //播放第一条并加入Timer设定切换间隔时间
        [self msgChange];
        [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(msgChange) userInfo:nil repeats:YES];
    }
    - (void)msgChange {
    
        if (self.msgCount < self.messageArray.count) {
            self.scrollLabel.text = [self.messageArray objectAtIndex:self.msgCount];
            self.msgCount++;
        } else {
            self.scrollLabel.text = @"no message";//此处删除可以改为循环滚动播放
        }
        
        [self.scrollLabel sizeToFit];
        CGRect frame = self.scrollLabel.frame;
        frame.origin.x = [UIScreen mainScreen].bounds.size.width;
        self.scrollLabel.frame = frame;
        
        [UIView beginAnimations:@"scrollLabelTest" context:NULL];
        [UIView setAnimationDuration:5.0f];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationRepeatAutoreverses:NO];
        [UIView setAnimationRepeatCount:0];
        
        frame = self.scrollLabel.frame;
        frame.origin.x = -frame.size.width;
        self.scrollLabel.frame = frame;
        [UIView commitAnimations];
    }
  • 相关阅读:
    网络负载均衡LVS
    JS 模仿红绿灯(控制台)
    【转】wrk 压力测试的 lua脚本
    linux开机 自动挂载和启动jar包
    【转】jprofiler linux配置需要监听的程序的端口
    时间复杂度总结
    Windows Subsystem for Linux (WSL) 安装
    敬畏用户
    Golang语言HTTP客户端实践
    Groovy入门常用语法
  • 原文地址:https://www.cnblogs.com/liuliuliu/p/4906736.html
Copyright © 2011-2022 走看看