iOS Swift - 从右到左自动滚动UILabel

时间:2016-06-19 07:09:38

标签: ios swift uilabel

这两列需要自动滚动(如选框)。但我这样做有问题。我找到了两个解决方案,但不幸的是,这些解决方案都没有。

  1. https://github.com/cbess/AutoScrollLabel
  2. https://github.com/cbpowell/MarqueeLabel
  3. 非常感谢任何帮助。

    enter image description here

1 个答案:

答案 0 :(得分:-1)

试试这个:

    let label = UILabel()

override func viewDidLoad() {
    super.viewDidLoad()
    label.frame = CGRectMake(320, 100, 200, 60)
    label.text = "This is my music line"
    self.view!.addSubview(label)
    NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: #selector(self.LabelAnimate), userInfo: nil, repeats: true)
}

func LabelAnimate() {
    UIView.animateWithDuration(3.0, delay: 0.0, options: .TransitionNone, animations: {() -> Void in
    self.label.frame = CGRectMake(-320, 100, 200, 60)
        }, completion: {(isDone: Bool) -> Void in
            self.label.frame = CGRectMake(320, 100, 200, 60)
    })
}
}