gpt4 book ai didi

ios - 无法将进度条重置为 0%

转载 作者:行者123 更新时间:2023-11-28 05:33:44 25 4
gpt4 key购买 nike

我的应用程序中有一个圆形进度条,它似乎运行良好。但是,出于某种原因,我无法缩小进度条。

它的基本功能是显示用户已花费的预算百分比。然而,用户也可以添加信用交易,当然你会希望减少进度条,因为他们增加了他们的总预算。然而,它似乎并没有这样做。我还需要在重置预算时将其重置为 0%,但这是行不通的。

这是进度圈的代码:

var progress: CGFloat = 0

class ProgressCircle: UIView {

override func drawRect(rect: CGRect) {
var ctx = UIGraphicsGetCurrentContext()

var innerRadiusRatio: CGFloat = 0.6

var path: CGMutablePathRef = CGPathCreateMutable()
var startAngle: CGFloat = CGFloat(-M_PI_2)
var endAngle: CGFloat = CGFloat(-M_PI_2) + min(1.0, progress) * CGFloat(M_PI * 2)
var outerRadius: CGFloat = CGRectGetWidth(self.bounds) * 0.5 - 1.0
var innerRadius: CGFloat = outerRadius * innerRadiusRatio
var center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect))

CGPathAddArc(path, nil, center.x, center.y, innerRadius, startAngle, endAngle, false)
CGPathAddArc(path, nil, center.x, center.y, outerRadius, endAngle, startAngle, true)
CGPathCloseSubpath(path)
CGContextAddPath(ctx, path)

CGContextSaveGState(ctx)
CGContextClip(ctx)
CGContextDrawImage(ctx, self.bounds, UIImage(named: "RadialProgressFill").CGImage)
CGContextRestoreGState(ctx)
}

这就是我目前尝试重置它的方式:

    progress = 0.00

进度是这样计算的:

        percent = 100*totalSpendingsCounter/(currencyDouble + totalCreditCounter)
let nf = NSNumberFormatter()
nf.numberStyle = .DecimalStyle

if percent > 100 {
percentageDisplay.text = "100%"
} else {
var percentString = nf.stringFromNumber(percent) + "%"
percentageDisplay.text = percentString
}

progress = CGFloat(percent/100)

有什么想法吗?

最佳答案

首先,progress 应该是 ProgressCircle 的属性,而不是全局变量。其次,需要在设置时标记为需要重新显示:

class ProgressCircle: UIView {

var progress: CGFloat = 0 {
didSet {
setNeedsDisplay()
}
}

(The rest of your code...)

关于ios - 无法将进度条重置为 0%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26151658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com