I made a custom cell that has progressView in it.
I set the timer and every second it updates progressbar.
Everything works fine when I use color such as UIcolor.red, UIcolor.green.
The problem occurs when I modify its color or use custom color creaded by hexcode. The progressBar starts at 0.25 point and until it goes beyond that point, it doesn't update.
enter image description here This is unexpected behavior.
import UIKit
class ViewController: UITableViewController {[![enter image description here][3]][3]
var time = 0
var progressNumber:Float = 0.2
let dummyArray = ["Pull Up","IOS","Strecthing","Bench Press"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "progreeCell", bundle: nil), forCellReuseIdentifier: "CustomCell")
tableView.rowHeight = 60
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
}
@objc func updateTime() {
progressNumber += 0.1
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
progressNumber += 0.03
tableView.reloadData()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dummyArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! progreeCell
cell.textLabel?.text = dummyArray[indexPath.row]
cell.progressBar.progress = progressNumber / Float(indexPath.row + 1)
cell.progressBar.alpha = 0.5
cell.progressBar.progressViewStyle = .bar
let color = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)
cell.progressBar.progressTintColor = color
return cell
}
}
