Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move text from right to left in iOS programmatically

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. I am developing AVAudioplayer. so in the top side of UIViewController the text will move from right to left.

like image 786
user3222991 Avatar asked Dec 02 '22 20:12

user3222991


1 Answers

First of all you take a label in your view and set its frame out of view as following.

 - (void)viewDidLoad
{
    [super viewDidLoad];

    la = [[UILabel alloc]initWithFrame:CGRectMake(320, 100, 200, 60)];

    la.text = @"This is my music line";

    [self.view addSubview:la];

    [NSTimer scheduledTimerWithTimeInterval:2.0
                                     target:self
                                   selector:@selector(LabelAnimation)
                                   userInfo:nil
                                    repeats:YES];

}

Now that label give animation as below method called in ViewDidLoad

-(void)LabelAnimation
{
    [UIView animateWithDuration:3.0f delay:0.0f options:UIViewAnimationOptionTransitionNone animations:^{
        la.frame = CGRectMake(-320, 100, 200, 60);
    } completion:^(BOOL finished)
     {
         la.frame = CGRectMake(320, 100, 200, 60);
     }];

}

output is below.

enter image description here

like image 198
Kirit Modi Avatar answered Dec 28 '22 23:12

Kirit Modi