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

1 uiprogressview ios swift

我已经创建UIProgressView并以UILabel编程方式.我希望我的进度条每秒更新一次并在屏幕上显示进度并更新标签值.所有这一切都应该在电话会议上完成viewDidLoad().

Ish*_*ika 8

取一个类型的变量Timer?,然后只需从你的viewDidLoad方法启动你的计时器,它将在每一秒后接收一次调用.然后只需更新该方法中的值progressBar.progresslabel.text值,如下所述:

  1. 拿一个变量

    var timer:Timer?
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在你的viewDidLoad使用中

    timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(self.updateProgressAndLabelValue), userInfo: nil, repeats: true)
    
    Run Code Online (Sandbox Code Playgroud)
  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)"      
    }
    
    Run Code Online (Sandbox Code Playgroud)