码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 滚动label(LED,跑马灯等) 快速实现源码

时间:2015-07-29 19:22:15      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

ios  滚动label  快速实现源码。这里使用的两个label,挪动frame实现。简单使用,这里仅抛砖引玉而已




技术分享

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *str = @"I love you,IOS-文字滚动的Label!";
    
    self.scrollLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,self.view.frame.size.width, 44)];
    self.scrollLabel.text = str;
    [self.view addSubview:self.scrollLabel];

    
    self.secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.scrollLabel.frame.origin.x+self.scrollLabel.frame.size.width, self.scrollLabel.frame.origin.y, self.scrollLabel.frame.size.width, self.scrollLabel.frame.size.height)];
    self.secondLabel.font = self.scrollLabel.font;
    self.secondLabel.text = self.scrollLabel.text;
    [self.view addSubview:self.secondLabel];
    
    [self addAnimation];
//    [[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(addAnimation) userInfo:nil repeats:YES] fire];
}

- (void)addAnimation{
    CGRect scrollFrame = self.scrollLabel.frame;
    CGRect secondFrame = self.secondLabel.frame;
    
    [UIView animateWithDuration:4 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        self.scrollLabel.frame = CGRectMake(-self.scrollLabel.frame.size.width, self.scrollLabel.frame.origin.y, self.scrollLabel.frame.size.width, self.scrollLabel.frame.size.height);
        self.secondLabel.frame = CGRectMake(0, self.secondLabel.frame.origin.y, self.secondLabel.frame.size.width, self.secondLabel.frame.size.height);
    } completion:^(BOOL finished) {
        self.scrollLabel.frame = scrollFrame;
        self.secondLabel.frame = secondFrame;
        [self addAnimation];
    }];
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

iOS 滚动label(LED,跑马灯等) 快速实现源码

标签:

原文地址:http://blog.csdn.net/lihongli528628/article/details/47131123

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!