How to move text from right to left in iOS programmatically

后端 未结 9 1801
野趣味
野趣味 2020-12-28 11:33

I want to show some text in my app like moving text (Scrolling with animation from right to left). How to do this programmatically?

I took UIViewcontroller

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 11:39

    IN Swift you can implement it like this

    override func viewDidLoad() {
        super.viewDidLoad()
    
        marqueeLabel = UILabel(frame: CGRectMake(320, 100, 400, 60))
        marqueeLabel.text = "Your music title here"
        self.view.addSubview(marqueeLabel)
    
        UIView.animateWithDuration(10.0, delay: 0.0, options: [.Repeat], animations: { () -> Void in
            self.marqueeLabel.frame = CGRectMake(-320, 100, 400, 60)
            }, completion: { (finished: Bool) -> Void in
                self.marqueeLabel.frame = CGRectMake(320, 100, 400, 60)
        });
    }
    

提交回复
热议问题