我想知道是否有一种方法来启用文本的水平滚动,即选取框类型的文本。我用过这个库:https://github.com/cbpowell/MarqueeLabel并将“MarqueeLabel.Swift”文件添加到我的应用程序中。但到目前为止,它没有显示出我想要的字幕效果。
我是这样实现的:
class ViewController: UIViewController
{
@IBOutlet weak var marqueeLabel: MarqueeLabel!
override func viewDidLoad() {
super.viewDidLoad()
self.marqueeLabel.tag = 101
self.marqueeLabel.type = .Continuous
self.marqueeLabel.speed = .Duration(5)
self.marqueeLabel.animationCurve = .EaseInOut
self.marqueeLabel.fadeLength = 10.0
self.marqueeLabel.leadingBuffer = 30.0
self.marqueeLabel.trailingBuffer = 20.0
self.marqueeLabel.restartLabel()
}
}
我已经根据MarqueeLabel Swift中的解决方案在接口构建器中设置了自定义类,但不起作用。还是不行
所有我得到的只是一个标签显示没有选框效果(或水平文本滚动)。
P.S:我也是iOS开发的新手。另外,在实现这个库之前,我尝试使用UIScrollView和UITextView。我不能使用UIWebView,因为我试图在TVOS中实现这一点。
我的问题是:
1.我的代码哪里出错了?
1.是否有其他方法可以使用Swift显示字幕效果?
先谢了。
8条答案
按热度按时间ars1skjm1#
我使用了这段代码让我的标签像跑马灯一样滚动:
是的,成功了。
2izufjch2#
更新为Swift 3,不使用任何第三方库或Pod
特别鸣谢:
https://stackoverflow.com/users/8303852/kartik-patel
https://stackoverflow.com/users/8388863/sid-patel
单击此处查看1演示
hpxqektj3#
简单选框- Swift 4.0:
qnyhuwrf4#
在SWIFT 3中:
moiiocjp5#
由于最初的问题与tvOS有关,我刚刚错误地发现(经过几周的搜索!)tvOS 12 beta已经实现了:
只有当祖先被聚焦时(比如当我们向电影海报添加标题并滚动到它时),才能获得字幕效果,当然,如果这是目标,可以直接从TVUIKit使用TVPosterView(比如this example),但它仍然适用于单个标签。
uujelgoq6#
你应该像这样使用,然后它会工作。
注意:你可能会面临性能问题,因为它在线程中使用递归,所以为了更好的性能,你应该使用CATextLayer和CAScrollLayer。
jckbn6z77#
在Swift 4
代码
rjzwgtxy8#
在Swift 5.8中创建自定义视图。它对我起作用
}然后你的视图控制器
}