Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Sunday, December 20, 2015

How to move text from right to left in ios programatically

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 by Agent Chocks. for How to move text from right to left in ios programatically


you could try this one

[UIView animateWithDuration:15.0f animations:^{          Moving_Cloud.frame = CGRectMake(320.0f, 30.0f, Moving_Cloud.frame.size.width, Moving_Cloud.frame.size.height);      }                       completion:^(BOOL finished){                       }];  

here " Moving_Cloud " is my image view so likewise you can try for your label.

Answer by Himanshu Joshi for How to move text from right to left in ios programatically


Yo can use UIView Animation Blocks for that

 [UIView animateWithDuration:5.0f delay:0.0f options:UIViewAnimationOptionTransitionNone animations:^{              yourLabel.center = CGPointMake(0, yourLabel.center.y);          } completion:NULL ];  

And if you want something like autoreverses

[UIView animateWithDuration:5.0f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState animations:^{              yourLabel.center = CGPointMake(0, yourLabel.center.y);          } completion:NULL ];  

Answer by Adithya for How to move text from right to left in ios programatically


Use the below method

- (void)marqueeLabel:(UILabel *)label  {      __block UILabel *labelToBeMarqueed = label;      __block CGRect labelFrame = labelToBeMarqueed.bounds;      labelFrame.origin.x = [UIScreen mainScreen].bounds.size.width;      labelToBeMarqueed.frame = labelFrame;      [UIView animateWithDuration:2.0f                   animations:^{                       labelFrame.origin.x = -[UIScreen mainScreen].bounds.size.width;                       labelToBeMarqueed.frame = labelFrame;                   } completion:^(BOOL finished) {                       [self marqueeLabel:label];                   }];  }  

Pass the label that you want to move from right to left to this method. Add a condition to stop the animation as this method loops continuously. You can change the animation duration as required.

Answer by Kirit Modi for How to move text from right to left in ios programatically


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

Answer by user1554498 for How to move text from right to left in ios programatically


 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){                       }];  

Answer by NIKETA SETH for How to move text from right to left in ios programatically


//Call this method where you need this. // and in this method write this 4 lines of code

[self Message:@"test"];    - (void)Message:(NSString *)messageString  {  UILabel *label = [[UILabel alloc] initWithFrame:(CGRectMake(321, 20, 300, 30))];  label.text = messageString;  label.backgroundColor = [UIColor clearColor];  [self.view addSubview:label];  [UIView beginAnimations:@"test" context:nil];  [UIView setAnimationDuration:3];  [UIView setAnimationDidStopSelector:@selector(Message:)];  [UIView setAnimationDelegate:self];    label.frame = CGRectMake(-100, 20, 300, 30);  [UIView commitAnimations];  }    enter code here  

It works..


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 71

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.