如何在Swift中使用MarqueeLabel? [英] How to use MarqueeLabel in Swift?

查看:254
本文介绍了如何在Swift中使用MarqueeLabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以启用文本的水平滚动,即选取框类型的文本.我使用了这个库: https://github.com/cbpowell/MarqueeLabel-Swift 和在我的应用程序中添加了"MarqueeLabel.Swift"文件.但是到目前为止,它还没有显示出我想要的字幕效果.

I want to know if there's a way to enable horizontal scrolling of text i.e., marquee type text. I have used this library: https://github.com/cbpowell/MarqueeLabel-Swift and added the "MarqueeLabel.Swift" file to my application. But so far, it doesn't show the marquee effect that I wanted.

这是我的实现方式:

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中的解决方案在接口构建器中设置了自定义类斯威夫特无法正常工作" .仍然不起作用.

I have set the custom class in the interface builder according to the solution in "MarqueeLabel Swift not working" . It still doesn't work.

我得到的只是一个没有选框效果(或水平文本滚动)显示的标签.

All I get is just a label displaying without the marquee effect (or horizontal text scroll).

P.S:我也是iOS开发的新手.另外,在实现此库之前,我尝试使用UIScrollView和UITextView.而且我无法使用UIWebView,因为我试图在TVOS中实现它.

P.S: I am new to iOS development too. Also, I tried using UIScrollView and UITextView before implementing this library. And I cannot use UIWebView as I'm trying to implement this in TVOS.

我的问题是:

  1. 我在哪里弄错了代码?

  1. Where did I go wrong with the code?

是否有其他方法可以使用Swift显示字幕效果?

Is there an alternative way to display marquee effect using Swift?

谢谢.

推荐答案

我使用了这小段代码来使标签像选取框一样滚动:

I used this little piece of code for my label to scroll like marquee:

@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 })
}

是的,它有效.

这篇关于如何在Swift中使用MarqueeLabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆