在IOS中创建水平滚动字幕标签



我需要在IOS中创建可滚动的字幕标签。我发现它可以在安卓系统中使用。我为android找到了。字幕未在android中滚动但我找不到适用于ios的。

android:text="hello all how are you hello all how are you hello all how are you hello all how are you"
TextView txtView=(TextView) findViewById(R.id.marqueetext);
txtView.setSelected(true);
 <TextView
    android:id="@+id/marqueetext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:lines="1"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:text="hello all how are you hello all how are you hello all how are you hello all how are you"
    android:textColor="#ff4500" 
    />

使用ZCAnimatedLabel(第三方库)来达到您想要的效果。

使用MarqueLabel,非常容易使用&使生效

如果您使用的是Pod,那么您可以将示例代码集成并尝试如下:

Objective-C:

pod 'MarqueeLabel'
MarqueeLabel *lengthyLabel = [[MarqueeLabel alloc] initWithFrame:aFrame duration:8.0 andFadeLength:10.0f];

Swift:

pod 'MarqueeLabel/Swift'
var lengthyLabel = MarqueeLabel.init(frame: aFrame, duration: 8.0, fadeLength: 10.0)
marqueeLabel.type = .Continuous
marqueeLabel.scrollDuration = 5.0
marqueeLabel.animationCurve = .EaseInOut
marqueeLabel.fadeLength = 10.0
marqueeLabel.leadingBuffer = 30.0
marqueeLabel.trailingBuffer = 20.0


使用Web视图的另一个解决方案:

String marquee = "<html><body><marquee>This is sample marquee</marquee></body></html>"
webview.loadData(marquee, "text/html", null);