ios – 如何在Swift中使用MarqueeLabel?
发布时间:2020-12-14 18:57:29 所属栏目:百科 来源:网络整理
导读:我想知道是否有一种方法可以启用文本的水平滚动,即字幕类型文本.我使用过这个库: https://github.com/cbpowell/MarqueeLabel-Swift并将“MarqueeLabel.Swift”文件添加到我的应用程序中.但到目前为止,它并没有显示出我想要的效果. 这是我实现它的方式: cla
我想知道是否有一种方法可以启用文本的水平滚动,即字幕类型文本.我使用过这个库:
https://github.com/cbpowell/MarqueeLabel-Swift并将“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 not working”中的解决方案在界面构建器中设置了自定义类 我得到的只是一个没有选框效果(或水平文字滚动)的标签. P.S:我也是iOS开发的新手.此外,我在实现此库之前尝试使用UIScrollView和UITextView.我不能使用UIWebView,因为我试图在TVOS中实现它. 我的问题是: >我的代码在哪里出错了? 提前致谢. 解决方法
我用我的标签的这一小段代码滚动像字幕:
@IBOutlet weak var firstLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() UIView.animateWithDuration(12.0,delay: 1,options: ([.CurveLinear,.Repeat]),animations: {() -> Void in self.firstLabel.center = CGPointMake(0 - self.firstLabel.bounds.size.width / 2,self.firstLabel.center.y) },completion: { _ in }) } 是的,它奏效了. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |