我使用
UIProgressView
显示百分比
所以我在故事板中采用了进度视图,并将其类别指定为
UIProgressView
这里如果我给
percentageView.progress =
任何值它完全填充..它应该只填充给定的值,how to fill percentageView with given value?
这些是故事板中
UIProgressView
的属性检查器值
代码:
class CandidateDashboardVC: UIViewController{
var progressValue : Float = 0
@IBOutlet weak var percentageView: UIProgressView!
override func viewDidLoad() {
super.viewDidLoad()
// percentageView.progress = 75.00
}
}
o/p:
var progressValue : Float = 0
然后
o/p:如果我在 didload 中给出
percentageView.progress = 75.00
,那么..它应该只填充进度的 75%,但它完全填充,为什么?请指导。
百分比表示为 0 到 1 之间的浮点数。
不是从 0 到 100。
所以,75% 就是 0.75。
如果将其设置为 0.75,您将看到您想要的进度。
在计算中只需除以 100。(或者,一开始就不要乘以 100)。
这在文档中进行了解释... https://developer.apple.com/documentation/uikit/uiprogressview/1619844-progress
如果有人正在寻找类似的解决方案,请尝试以下解决方案
let formatter = NumberFormatter()
formatter.maximumFractionDigits = 0
formatter.roundingMode = .down
progressView.progress += 0.01
lblTimer.text = formatter.string(from: progressView.progress * 100 as NSNumber)
progressView.setProgress(progressView.progress, animated: true)
if(progressView.progress == 10.0){
progressBarTimer.invalidate()
isRunning = false
buttonView.setTitle("Start", for: .normal)
}