iosswiftuiprogressview

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


Solution

  • 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