How to move text from right to left in iOS programmatically

后端 未结 9 1815
野趣味
野趣味 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条回答
  •  难免孤独
    2020-12-28 11:45

     UILabel*label=[[UILabel alloc]init];
        label.text=@"Song Name";
        label.frame=CGRectMake(321, 20, 300, 30);
        [self.view addSubview:label];
        [UIView beginAnimations:@"" context:nil];
        [UIView setAnimationDuration:20.0];
        label.frame=CGRectMake(0, 20, 300, 30);
    
        [UIView commitAnimations];
    

    Or you can try this out if you want to repeat the scrolling of the text

    UILabel*label=[[UILabel alloc]init];
        label.text=@"Song Name";
        label.frame=CGRectMake(321, 20, 300, 30);
        [self.view addSubview:label];
        [UIView animateWithDuration:5.0 delay:0.0 options: UIViewAnimationOptionRepeat
                         animations:^{
                             label.frame=CGRectMake(-100, 20, 300, 30);
                         }completion:^(BOOL finished){
                         }];
    

提交回复
热议问题