1

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

Swift
  • 1,074
  • 12
  • 46

1 Answers1

2

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

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • I am getting progress value from backend like 74 as Int, so i have tried like this `percentageView.progress = Float(data.user?.percentage ?? 0).truncatingRemainder(dividingBy: 100)` then o/p `progress value 1.0 test float value 74.0` – Swift Dec 07 '21 at 10:43
  • how do i get 74 as 0.74.. please guide me – Swift Dec 07 '21 at 10:43
  • 3
    Simply `Float(data.user?.percentage ?? 0)/100` – Paulw11 Dec 07 '21 at 11:00