1

I have created UIProgressView and UILabel programatically. I want my progressbar to get update every second and show the progress on screen and also update the label value. All of this should done on the call of viewDidLoad().

SimpleBeat
  • 747
  • 1
  • 10
  • 20
  • What did you try to accomplish this, or at least where did you start? – SimpleBeat May 15 '17 at 12:57
  • I am just learning Swift 3...so It is learning experiment for me. –  May 16 '17 at 12:46
  • I am sorry, I was only looking for a specific code from you, it's kind of a general agreement here on StackOverflow to show some code to get people started. Otherwise a question may become too general or too opinion-based. – SimpleBeat May 16 '17 at 13:19

1 Answers1

8

Take a variable of type Timer?, then simply start your timer from your viewDidLoad method which will receive call after every one second. Then simply update your progressBar.progress and label.text value in that method as mentioned below:

  1. Take a variable

    var timer:Timer?
    
  2. In your viewDidLoad use

    timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(self.updateProgressAndLabelValue), userInfo: nil, repeats: true)
    
  3. Make a function and do the needful

    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)"      
    }
    
SimpleBeat
  • 747
  • 1
  • 10
  • 20
Ishika
  • 2,187
  • 1
  • 17
  • 30