进度条设置进度
Progres Bar SetProgres
我有两个号码。当前分数和 maxScore。例如 0/1000。
我有几个级别。每个级别都有自己的经验。 1000、2000、3000。当用户得分从 0 到 1000 时,进度条从开始填充到结束。但是当用户已经获得 1000 分时,他现在应该获得 2000 分。然后进度条从中间开始填充,而不是像从0到1000那样从头开始填充。
@IBOutlet weak var progressBar:UIProgressView!
func SetProgress() {
let currentScore = getScore() //return Int
let maxScore = getMaxScore() // return Int
progressBar.progress = Float(currentScore / maxScore)
}
let currentScore = 25
let maxScore = 50
@IBOutlet weak var progress: UIProgressView!
progress.progress = Float(currentScore)/Float(maxScore)
我希望它会起作用
好的 - 您需要跟踪另一条信息...我们称之为“基本分数”。
用户从零开始,目标是 1000。随着他获得积分,您将进度设置为 1000 的百分比:
// supposing the curentScore is 900, maxScore is 1000
progress.progress = Float(currentScore)/Float(maxScore)
栏已填充 90%。
当用户达到 1000 时,您将新目标设置为 2000,并且您希望以百分比形式跟踪进度而不是 currentScore
到 maxScore
。相反,您想跟踪从 previous maxScore
到 new[=49 的进度=]maxScore
.
所以,像这样:
func setProgress() -> Void {
let currentScore = getScore()
let maxScore = getMaxScore()
// for example, if user is at:
// Level 1 == 0
// Level 2 == 1000
// Level 3 == 2000
let levelBase = getLevelBaseScore()
let curVal = Float(currentScore - levelBase)
let maxVal = Float(maxScore - levelBase)
progressBar.progress = curVal / maxVal
}
所以,getLevelBaseScore()
应该return上一关的最高分。
示例:
如果用户处于“1 级”并且他的当前分数是 750:
let currentScore = getScore() // returns 750
let maxScore = getMaxScore() // returns 1000
let levelBase = getLevelBaseScore() // returns Zero for Level 1
let curVal = Float(750 - 0) // == 750
let maxVal = Float(1000 - 0) // == 1000
// 750 / 1000 == 0.75 or 75% of the bar
progressBar.progress = curVal / maxVal
如果用户处于“2 级”并且他的当前分数是 1100:
let currentScore = getScore() // returns 1100
let maxScore = getMaxScore() // returns 2000
let levelBase = getLevelBaseScore() // returns 1000 for Level 2
let curVal = Float(1100 - 1000) // == 100
let maxVal = Float(2000 - 1000) // == 1000
// 100 / 1000 == 0.10 or 10% of the bar
progressBar.progress = curVal / maxVal
如果用户处于“2 级”并且他的当前分数是 1600:
let currentScore = getScore() // returns 1600
let maxScore = getMaxScore() // returns 2000
let levelBase = getLevelBaseScore() // returns 1000 for Level 2
let curVal = Float(1600 - 1000) // == 600
let maxVal = Float(2000 - 1000) // == 1000
// 600 / 1000 == 0.60 or 60% of the bar
progressBar.progress = curVal / maxVal
如果用户处于“3 级”并且他的当前分数是 2250:
let currentScore = getScore() // returns 2250
let maxScore = getMaxScore() // returns 3000
let levelBase = getLevelBaseScore() // returns 2000 for Level 3
let curVal = Float(2250 - 2000) // == 250
let maxVal = Float(3000 - 2000) // == 1000
// 250 / 1000 == 0.25 or 25% of the bar
progressBar.progress = curVal / maxVal
我有两个号码。当前分数和 maxScore。例如 0/1000。 我有几个级别。每个级别都有自己的经验。 1000、2000、3000。当用户得分从 0 到 1000 时,进度条从开始填充到结束。但是当用户已经获得 1000 分时,他现在应该获得 2000 分。然后进度条从中间开始填充,而不是像从0到1000那样从头开始填充。
@IBOutlet weak var progressBar:UIProgressView!
func SetProgress() {
let currentScore = getScore() //return Int
let maxScore = getMaxScore() // return Int
progressBar.progress = Float(currentScore / maxScore)
}
let currentScore = 25
let maxScore = 50
@IBOutlet weak var progress: UIProgressView!
progress.progress = Float(currentScore)/Float(maxScore)
我希望它会起作用
好的 - 您需要跟踪另一条信息...我们称之为“基本分数”。
用户从零开始,目标是 1000。随着他获得积分,您将进度设置为 1000 的百分比:
// supposing the curentScore is 900, maxScore is 1000
progress.progress = Float(currentScore)/Float(maxScore)
栏已填充 90%。
当用户达到 1000 时,您将新目标设置为 2000,并且您希望以百分比形式跟踪进度而不是 currentScore
到 maxScore
。相反,您想跟踪从 previous maxScore
到 new[=49 的进度=]maxScore
.
所以,像这样:
func setProgress() -> Void {
let currentScore = getScore()
let maxScore = getMaxScore()
// for example, if user is at:
// Level 1 == 0
// Level 2 == 1000
// Level 3 == 2000
let levelBase = getLevelBaseScore()
let curVal = Float(currentScore - levelBase)
let maxVal = Float(maxScore - levelBase)
progressBar.progress = curVal / maxVal
}
所以,getLevelBaseScore()
应该return上一关的最高分。
示例:
如果用户处于“1 级”并且他的当前分数是 750:
let currentScore = getScore() // returns 750
let maxScore = getMaxScore() // returns 1000
let levelBase = getLevelBaseScore() // returns Zero for Level 1
let curVal = Float(750 - 0) // == 750
let maxVal = Float(1000 - 0) // == 1000
// 750 / 1000 == 0.75 or 75% of the bar
progressBar.progress = curVal / maxVal
如果用户处于“2 级”并且他的当前分数是 1100:
let currentScore = getScore() // returns 1100
let maxScore = getMaxScore() // returns 2000
let levelBase = getLevelBaseScore() // returns 1000 for Level 2
let curVal = Float(1100 - 1000) // == 100
let maxVal = Float(2000 - 1000) // == 1000
// 100 / 1000 == 0.10 or 10% of the bar
progressBar.progress = curVal / maxVal
如果用户处于“2 级”并且他的当前分数是 1600:
let currentScore = getScore() // returns 1600
let maxScore = getMaxScore() // returns 2000
let levelBase = getLevelBaseScore() // returns 1000 for Level 2
let curVal = Float(1600 - 1000) // == 600
let maxVal = Float(2000 - 1000) // == 1000
// 600 / 1000 == 0.60 or 60% of the bar
progressBar.progress = curVal / maxVal
如果用户处于“3 级”并且他的当前分数是 2250:
let currentScore = getScore() // returns 2250
let maxScore = getMaxScore() // returns 3000
let levelBase = getLevelBaseScore() // returns 2000 for Level 3
let curVal = Float(2250 - 2000) // == 250
let maxVal = Float(3000 - 2000) // == 1000
// 250 / 1000 == 0.25 or 25% of the bar
progressBar.progress = curVal / maxVal