I am currently working on a quiz based iOS application. I wanted to add a progress bar that changed colors based on if the question was answered correctly or incorrectly. Based on if it was answered correctly or incorrectly, I want only that interval to change to green/red, not the whole bar. I have 50 intervals for the progress bar. Everything I have tried has resulted in the whole bar changing color instead of just the interval. I am pretty new to iOS development still and am struggling to figure this out.
let progress = Progress(totalUnitCount: 50)
challengeProgressBar.progress = 0.0
progress.completedUnitCount = 0
for i in 0..<index {
progress.completedUnitCount += 1
challengeProgressBar.setProgress(Float(self.progress.fractionCompleted), animated: true)
if (selectedAnswer[i] == Answers[i]){
challengeProgressBar.progressTintColor = UIColor.green
} else {
challengeProgressBar.progressTintColor = UIColor.red
}
}
The result I get is the very last color the loop produced. The whole bar is either red or green.