1

I am trying to update progress bar based on the server data. So, if value received (in %) is less than 90 then the progress bar should be green else it should be red in colour.

if (value >= 90) {
    progressBar.progressTintColor = UIColor.redColor()
} else 
{ 
    progressBar.progressTintColor = UIColor.greenColor()
}
progressBar.setProgress(Float(value)/100, animated : true)

The above code works fine except for range 0.01 - 0.05. Any value between this range always shows progress as 0.05 only. If I comment out the code to update color then it seems to be working fine.

I am updating everything on main thread. Also, I observed that calling this method from viewDidLoad and viewWillAppear does not impact the progress.

Similar question is posted in below link - UIProgressView doesn't update <=0.5 value after Changing ProgressTintColor

but, it is not yet answered.

Any help to solve this issue will be appreciated.

Community
  • 1
  • 1
Leena
  • 11
  • 3
  • `setProgress:` takes a value from 0.0 - 1.0. From your above code it seem `value` is more than 1.0. Try converting `value` value to an equivalent number in the range of 0.1 - 1.0. – Rishab May 20 '17 at 06:19
  • @Rishab, sorry for typo, I have corrected sample code above. I am already dividing it by 100.0f in my original code. Still issue exist. Thanks! – Leena May 20 '17 at 10:06
  • What color are you expecting it be if the progress is in between 0.01 or 1.0?? – Bilal May 20 '17 at 18:49
  • @Bilal : As mentioned in question also, I want the progress tint color to be red, if the value is greater than or equal to 90 else it should be green (i.e. 0.0 to 0.89). – Leena May 22 '17 at 04:25
  • @Leena, it's 3 years later since your post, but I was wondering if you eventually resolved the issue. I have the same issue where the progress doesn't reflect the value for range 0.01-0.05 when I change the progress tint color. – e.cho Oct 08 '20 at 01:10

1 Answers1

0

Try this

 DispatchQueue.main.async {
     if (value >= 90) {
        progressBar.progressTintColor = UIColor.redColor()
     } else 
     { 
        progressBar.progressTintColor = UIColor.greenColor()
     }
     progressBar.setProgress(value, animated : true)
    }
Vikash Kumar
  • 642
  • 1
  • 11
  • 25
  • 1
    I have mentioned in my question that I am executing the above code in main thread, but still it doesn't help. – Leena May 20 '17 at 10:25