Swift
Swift

Reputation: 1182

Unable to give min and max value to "UIProgressView" in Swift

I am using UIProgressView to show percentage

so i have taken progressview in storyboard and given its class as UIProgressView

here if i give any value to percentageView.progress = its totally filling.. it should fill only the given value, how to fill percentageView with given value?

these are the attribute inspector values in storyboard for UIProgressView

enter image description here

code:

class CandidateDashboardVC: UIViewController{

var progressValue : Float = 0

@IBOutlet weak var percentageView: UIProgressView!

override func viewDidLoad() {
    super.viewDidLoad()
// percentageView.progress = 75.00 

}
}

o/p: var progressValue : Float = 0 then

enter image description here

o/p: if i give percentageView.progress = 75.00 in didload then.. it should fill only 75% of progress but it is totally filling, why? please do guide.

enter image description here

Upvotes: 1

Views: 1811

Answers (2)

Farhan Maknojiya
Farhan Maknojiya

Reputation: 1

if someone is looking for similar try below solution

let formatter = NumberFormatter()
formatter.maximumFractionDigits = 0
formatter.roundingMode = .down
            
progressView.progress += 0.01
lblTimer.text = formatter.string(from: progressView.progress * 100 as NSNumber)
progressView.setProgress(progressView.progress, animated: true)
if(progressView.progress == 10.0){
    progressBarTimer.invalidate()
    isRunning = false
    buttonView.setTitle("Start", for: .normal)
}

Upvotes: 0

Fogmeister
Fogmeister

Reputation: 77661

Percentages are represented as a float from 0 to 1.

Not from 0 to 100.

So, 75% is 0.75.

If you set it to 0.75 you will see the progress you want.

In your calculation just divide by 100. (Or, don’t multiply by 100 in the first place).

This is explained in the docs… https://developer.apple.com/documentation/uikit/uiprogressview/1619844-progress

Upvotes: 2

Related Questions