Ch Hnsn
Ch Hnsn

Reputation: 107

Ios moving a label ( song title ) from right side to left side?

How to move a label? i would like to show a song title, moving from right side to left side with a duration that i can set. as you can see on a car radio. when the label if off the screen it should reappear from the right side

thank you

Upvotes: 1

Views: 2235

Answers (2)

Madhu
Madhu

Reputation: 2593

     UILabel *toastLabel = [[UILabel alloc]init*];
     toastLabel.text = @"Our toast text";
     [toastLabel setHidden:TRUE];
     [toastLabel setAlpha:1.0];
     CGPoint location;
     location.x = 0;
     location.y = 400;
     toastLabel.center = location;
     location.x = 500;
     location.y = 400;
     [toastLabel setHidden:FALSE];
     [UIView animateWithDuration:8 animations:^{
         toastLabel.alpha = 0.0;
         toastLabel.center = location;
     }];

Upvotes: 1

DivineDesert
DivineDesert

Reputation: 6954

Iphone dont provide such feature for UILabels, you need to animate labels for that.

Refer this link https://github.com/cbpowell/MarqueeLabel

Just drag and drop MarqueeLabel.h & MarqueeLabel.m files and create Label as follows:

MarqueeLabel *rightLeftLabel = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10, 260, self.view.frame.size.width-20, 20) rate:50.0f andFadeLength:10.0f];
rightLeftLabel.numberOfLines = 1;
rightLeftLabel.shadowOffset = CGSizeMake(0.0, -1.0);
rightLeftLabel.textAlignment = NSTextAlignmentRight;
rightLeftLabel.textColor = [UIColor colorWithRed:0.234 green:0.234 blue:0.234 alpha:1.000];
rightLeftLabel.backgroundColor = [UIColor clearColor];
rightLeftLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.000];
rightLeftLabel.marqueeType = MLRightLeft;
rightLeftLabel.text = @"This text is not as long, but still long enough to scroll, and scrolls the same speed but to the right first!";
[self.view addSubview:rightLeftLabel];

They have created UIView subclass and animating UILabels that are subviews of UIView.

Hope this helps you :)

Upvotes: 6

Related Questions