0

I have an app which updates a BLE device using iOSDFULibrary.

I have this function:

   func dfuProgressDidChange(for part: Int, outOf totalParts: Int, to progress: Int, currentSpeedBytesPerSecond: Double, avgSpeedBytesPerSecond: Double) {
       print("\t\(part)\t\(totalParts)\t\(progress)\t\(currentSpeedBytesPerSecond)\t\(avgSpeedBytesPerSecond)")
}

When the update is going on, I want my UIProgressView to move accordingly progress and be filled fully when the progress reaches 100.

What I have so far is:

@IBOutlet weak var progressView: UIProgressView!


progressView.progressViewStyle = .default
progressView.tintColor = .orange
progressView.progressTintColor = .orange
progressView.backgroundColor = .none
progressView.progress = Float(progress)
progressView.setProgress(100.0, animated: true)
Lilya
  • 495
  • 6
  • 20

2 Answers2

1
func dfuProgressDidChange(for part: Int, outOf totalParts: Int, to progress: Int, currentSpeedBytesPerSecond: Double, avgSpeedBytesPerSecond: Double) {
    let progress = Float(part) / Float(total)
    progressView.setProgress(progress, animated: true)
}

Also I notice that you set 100 progress to ProgressView.

progressView.setProgress(100.0, animated: true)

ProgressView maximum progress is 1.0

open class UIProgressView : UIView, NSCoding {

    open var progress: Float // 0.0 .. 1.0, default is 0.0. values outside are pinned.

}
  • Hi @Данил Блинов and thank you so much for your comment. The thing is, I have also tried setting both ```progressView.setProgress(progress, animated: true)``` and ```progressView.setProgress(1.0, animated: true)```, but it gave no results. When put to ```1.0```, the animation just fills a half of a UIProgressView and from that moment it slows down and reaches the end slowly. – Lilya Jun 26 '20 at 14:02
0

It turned out that what I had to avoid putting to my code was:

progressView.setProgress(100.0, animated: true)

I deleted it. The max value as it was mentioned earlier is 1.0, and my progress is 0-100. So, in order the progressView to show the change, I have to firstly convert my progress to Float and then divide it by 100, so we have the max value of 1.0 and not 100:

progressView.progress = Float(progress)/100

So, now my code looks like this:

@IBOutlet weak var progressView: UIProgressView!


progressView.progressViewStyle = .default
progressView.tintColor = .orange
progressView.progressTintColor = .orange
progressView.backgroundColor = .none

    func dfuProgressDidChange(for part: Int, outOf totalParts: Int, to progress: Int, currentSpeedBytesPerSecond: Double, avgSpeedBytesPerSecond: Double) {
        print("\t\(part)\t\(totalParts)\t\(progress)\t\(currentSpeedBytesPerSecond)\t\(avgSpeedBytesPerSecond)")
        
        progressView.progress = Float(progress)/100
    }
Lilya
  • 495
  • 6
  • 20