所以我想在 XCode 项目中保留一个 Score
。但我希望它像 0.01, 0.02...
直到到达 1.00
并从 1
继续像 1, 2、3...
我当前的代码如下所示:
var Highscore = 0
var Score = 0
...
@IBAction func Action(sender: AnyObject) {
if (Score < 100) {
Score++
HighScoreLabel.text = "HighScore:\(Score)"
} else if (Score >= 100) {
Score += 100
HighScoreLabel.text = "HighScore:\(Score)"
我已经尝试创建一个除分数的变量,我尝试将其设为 double (但我想要 1, 2..
而不是 1.00, 2.00
),我不知道该怎么办。
如果可以的话请帮助我,并随时进行编辑。
最佳答案
func action() {
if (score < 100) {
score += 1
let someScore = score < 1 ? String(format: "%.2f", score) : String(format: "%.f", round(score))
println("HighScore:\(someScore)")
} else if (score >= 100) {
score += 100
let someScore = score < 1 ? String(format: "%.2f", score) : String(format: "%.0f", round(score))
println("HighScore:\(someScore)")
}
}
这应该可以。
编辑:
使用了您的代码。
关于ios - 使用 swift 在 XCode 中记分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30282611/