我已经创建UIProgressView并以UILabel编程方式.我希望我的进度条每秒更新一次并在屏幕上显示进度并更新标签值.所有这一切都应该在电话会议上完成viewDidLoad().
取一个类型的变量Timer?,然后只需从你的viewDidLoad方法启动你的计时器,它将在每一秒后接收一次调用.然后只需更新该方法中的值progressBar.progress和label.text值,如下所述:
拿一个变量
var timer:Timer?
Run Code Online (Sandbox Code Playgroud)在你的viewDidLoad使用中
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(self.updateProgressAndLabelValue), userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud)发挥作用,做到需要
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)| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |