Set a constant size height of the progress while animating iOS

22 Views Asked by At

I've set up a ProgressView on the TableView cell and dynamically assign progress values to each cell. I aim to maintain a constant size for the progress view when updating the progress value. By default, the progress bar adjusts its size dynamically based on the progress value assigned to each TableView cell.

Code:-

GuideView Controller Class

import UIKit

class GuidePostView: UIViewController, UITableViewDataSource,UITableViewDelegate {

@IBOutlet weak var chapterListTblView: UITableView!

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return questions.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell", for: indexPath) as! TestCell
    let ques = questions[indexPath.row]
    let progressPercentage = Float(ques.answerGiven!)/Float(ques.totalQuestion!)
    cell.chapterProgress.setProgress(progressPercentage.rounded(toPlaces: 2), animated: true)
    return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
     return 75
     }
}

GuideCell Class

class GuideCell: UITableViewCell {

@IBOutlet weak var chapterProgress: UIProgressView!

override func awakeFromNib() {
    super.awakeFromNib()
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    }
}

Output:-

Gif

My question is, how can I set a constant size height of the progress while animating? I've tried the above code, but haven't achieved any results yet.

0

There are 0 best solutions below