简体   繁体   中英

iOS Swift - Autoscroll UILabel from Right to Left

These two columns needed to be scrolled automatically (like marquee). But I am having problem to do this. I found two solutions but unfortunately none of these worked.

  1. https://github.com/cbess/AutoScrollLabel
  2. https://github.com/cbpowell/MarqueeLabel

Any help is greatly appreciated.

在此处输入图片说明

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM