UILabel 从右向左和向后动画
UILabel to animate left and back again from right
所以我想要实现的是有一个 UILabel 文本,它应该像 LED 广告牌一样动画显示新闻和商场外的各种其他文本等。UILabel 不应该改变位置,但其中的文本应该从它的当前位置朝向 UILabel 的左侧边界,然后再次从右侧返回,有点像队列。示例文本是:
动画前:
"I would like to implement this..."
动画期间:
"like to implement this... I would "
"ment this... I would like to imple"
等等
这应该持续到我希望动画保留为止,可能永远持续下去。
请任何帮助都会创造奇迹。谢谢
这是一个简单的解决方案:
- (void)viewDidLoad {
[super viewDidLoad];
self.label.text = @"I would like to implement this...";
self.timer = [NSTimer timerWithTimeInterval:0.3f target:self
selector:@selector(animateText)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)animateText{
NSMutableString *str = [NSMutableString stringWithString:[self.label.text substringFromIndex:1]];
[str appendString:[self.label.text substringToIndex:1]];
self.label.text = str;
}
pod MarqueeLabel
MarqueeLabel 提供此功能。只需将标签的 class 名称设置为 MarqueeLabel,如下所示:-
@IBOutlet weak var lblLocation: MarqueeLabel!
根据您的要求设置属性:-
- 时长
- 淡化长度
- 选取框类型
所以我想要实现的是有一个 UILabel 文本,它应该像 LED 广告牌一样动画显示新闻和商场外的各种其他文本等。UILabel 不应该改变位置,但其中的文本应该从它的当前位置朝向 UILabel 的左侧边界,然后再次从右侧返回,有点像队列。示例文本是:
动画前:
"I would like to implement this..."
动画期间:
"like to implement this... I would "
"ment this... I would like to imple" 等等
这应该持续到我希望动画保留为止,可能永远持续下去。
请任何帮助都会创造奇迹。谢谢
这是一个简单的解决方案:
- (void)viewDidLoad {
[super viewDidLoad];
self.label.text = @"I would like to implement this...";
self.timer = [NSTimer timerWithTimeInterval:0.3f target:self
selector:@selector(animateText)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)animateText{
NSMutableString *str = [NSMutableString stringWithString:[self.label.text substringFromIndex:1]];
[str appendString:[self.label.text substringToIndex:1]];
self.label.text = str;
}
pod MarqueeLabel
MarqueeLabel 提供此功能。只需将标签的 class 名称设置为 MarqueeLabel,如下所示:-
@IBOutlet weak var lblLocation: MarqueeLabel!
根据您的要求设置属性:-
- 时长
- 淡化长度
- 选取框类型