user3222991 user3222991 - 2 months ago 6
iOS Question

How to move text from right to left in ios programatically

I want to show some text in my app like moving text (Scrolling with animation from right to left). I don't know how to do this Programatically?

I took

UIViewcontroller
.I am developing
AVAudioplayer
.so in the top side of
UIViewController
the text will move from right to left.

Answer

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