我有一个UILabel,想像HTML中的字幕标记一样滚动,我应该怎么做?

#define LEFTSCROLLDIRECTION 0
#define RIGHTSCROLLDIRECTION 1

MarqueeLabel *marquee = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10, 10, 300, 30)];
label.scrollDirection = LEFTSCROLLDIRECTION;
[self.view addSubview:marquee];


编辑

我已经找到了this类,似乎一开始就可以使用。

但这有一个问题..如果我在UINavigationController中向前导航并在一段时间后弹出该pushViewController,则autoScrollLabel将停止动画。

AutoScrollLabel *autoScrollLabel = [[AutoScrollLabel alloc] init];
autoScrollLabel.text = @"Hi Mom!  How are you?  I really ought to write more often.";
autoScrollLabel.textColor = [UIColor yellowColor];

最佳答案

查看this开源组件,实际上称为MarqueeLabel。

这真的很容易。

08-05 22:10