如何在viewDidLoad()方法中更新Swift3中的UIProgressVeiw?

时间:2017-05-15 12:43:26

标签: ios swift uiprogressview

我以编程方式创建了UIProgressViewUILabel。我希望我的进度条每秒更新一次并在屏幕上显示进度并更新标签值。所有这些都应该在viewDidLoad()的调用下完成。

1 个答案:

答案 0 :(得分:8)

选择Timer?类型的变量,然后只需从viewDidLoad方法启动计时器,该方法将在每一秒钟后接听电话。 然后,只需更新该方法中的progressBar.progresslabel.text值,如下所述:

  1. 拿一个变量

    var timer:Timer?
    
  2. viewDidLoad使用

    timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(self.updateProgressAndLabelValue), userInfo: nil, repeats: true)
    
  3. 制作一个功能并做必要的

    func updateProgressAndLabelValue(){
        //You will get call every second here
        //You can update the progressBar and Label here only
        //For example: yourProgressViewOutlet.progress = updatedValue
        //And lblYOuLabel.text = "\(updatedValue)"      
    }