Ios将标签(歌曲标题)从右侧移到左侧?

时间:2013-11-26 05:23:23

标签: ios uilabel

如何移动标签? 我想显示一个歌曲标题,从右侧移动到左侧,持续时间我可以设置。正如你在汽车收音机上看到的那样。当标签离开屏幕时,它应该从右侧重新出现

谢谢

2 个答案:

答案 0 :(得分:5)

Iphone不为UILabels提供此类功能,您需要为其设置动画标签。

请参阅此链接 https://github.com/cbpowell/MarqueeLabel

只需拖放MarqueeLabel.h& MarqueeLabel.m文件并创建Label如下:

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];

他们创建了UIView子类并为UIVabel设置动画,这些UILabels是UIView的子视图。

希望这可以帮到你:)

答案 1 :(得分:1)

     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;
     }];
相关问题