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



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

取一个类型 Timer? 的变量,然后只需从 viewDidLoad 方法启动计时器,该方法将每隔一秒接收一次调用。然后只需更新该方法中的progressBar.progress值和label.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)"      
    }
    

最新更新