Krunal Nagvadia
Krunal Nagvadia

Reputation: 1162

Swift: Change the Label text while progress view is complete 1.0

I have a progressView with the label. when the page is loaded progress bar is started wit the value 0.0 and upto 1.0. This is my progressView code.

Function

@objc func updateProgress() {
        progressValue = progressValue + 0.01
        self.progressView.progress = Float(progressValue)

        if progressValue != 1.0 {
            progressView.isHidden = false
            self.perform(#selector(updateProgress), with: nil, afterDelay: 0.2)
        }
    }

Call The function in ViewDidLoad ad below.

self.perform(#selector(updateProgress), with: nil, afterDelay: 0.2)`

I want the change the label text from "Wait a while" to "Enter OTP Manually" when my progress view is complete its process or it's Value is become 1.0.

Upvotes: 2

Views: 1697

Answers (1)

Kamran
Kamran

Reputation: 15238

Current if-statement looks fine but i would go with this to avoid any float rounding issue,

    if progressValue < 1.0 { // Considering 1.0 is the max value.
        progressView.isHidden = false
        self.perform(#selector(updateProgress), with: nil, afterDelay: 0.2)
    } else {
       self.label.text = "Enter OTP Manually"
    }

Upvotes: 3

Related Questions