How to move text from right to left in iOS programmatically

后端 未结 9 1785
野趣味
野趣味 2020-12-28 11:33

I want to show some text in my app like moving text (Scrolling with animation from right to left). How to do this programmatically?

I took UIViewcontroller

9条回答
  •  萌比男神i
    2020-12-28 11:58

    Add View with background colour.

    UIView *animatedLblView = [[UIView alloc]initWithFrame:CGRectMake(0, 75, self.view.frame.size.width, 30)];
    animatedLblView.backgroundColor = [UIColor colorWithRed:0.00 green:0.34 blue:0.61 alpha:1.0];
    [self.view addSubview:animatedLblView];
    //Our animated component(UIButton)
    _animatingButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width+100, 30)];
    [_animatingButton setTitle:@"Upload documents, please contact 1234567890" forState:UIControlStateNormal];
    [animatedLblView addSubview:_animatingButton];
    //Timer
    [NSTimer scheduledTimerWithTimeInterval:1.0
                                     target:self
                                   selector:@selector(LabelAnimation)
                                   userInfo:nil
                                    repeats:nil];
    
    -(void)LabelAnimation {
        //Set animation
        [UIView animateWithDuration:10.0f delay:0.0f options:UIViewAnimationOptionTransitionNone animations:^{
        _animatingButton.frame = CGRectMake(-(self.view.frame.size.width+100), 0, self.view.frame.size.width+100, 30);
        } completion:^(BOOL finished) {
         _animatingButton.frame = CGRectMake(self.view.frame.size.width, 0, 0, 30);
            // Call the same function
            [self LabelAnimation];
         }];
    }
    

提交回复
热议问题