Alicia I
Alicia I

Reputation: 13

How do you make progress bar increase when button is clicked ? Swift

I want the progress bar to increase when a "next button is pressed" as further in my code i have if, else statements saying,

@IBAction func nextButton(_ sender: UIButton) {
    if progressBar.progress == Float(0.25) {
        labelText.text = "first label"
    }
    else if progressBarCY.progress == Float(0.50) {
        labelText.text = "second label"
    }
}

Upvotes: 1

Views: 4537

Answers (1)

Roma Kavinskyi
Roma Kavinskyi

Reputation: 313

First, outside the function, you need to set up the progress Bar Value.

progressBar.progress = 0

Then inside nextButton function, you can add more value to your progress bar.

@IBAction func nextButton(_ sender: UIButton) {
progressBar.progress += 0.25
if progressBar.progress == 0.25 {
labelText.text = "first label" }
else if progressBar.progress == 0.50 {
labelText.text = "second label" } }

Upvotes: 1

Related Questions