如何设置每次 addMoreCredits - 按下按钮时,它将从 usersCredits 中减去1并将1添加到 amountOfCreditInGame 并且我想设置 progressBar 以显示每次用户点击 addMoreCredits - 按钮时我尝试将进度条设置为1 - 1000但它没有工作 - 我想设置一旦 progressBar 达到1000, mainImage 将会改变
谢谢
@IBOutlet weak var mainImage: UIImageView!
@IBOutlet weak var amountOfCreditInGame: UILabel!
@IBOutlet weak var usersCredits: UILabel!
@IBOutlet weak var progressBar: UIProgressView!
var usersCredit = 0 {
didSet{
usersCredits.text = "Credit: \(credit)"
}}
var creditInGame = 0 {
didSet{
amountOfCreditInGame.text = "Credits in: \(creditInGame)"
}}
var gameProgress: Float = 1000.0
var credit = 0 {
didSet {
creditLabel.text = "Credit: \(credit)"
}
}
override func viewDidLoad() {
super.viewDidLoad()
self.gameProgress = 0
self.progressBar.progress = 0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func addMoreCredits(_ sender: Any) {
creditInGame += 1 + credit
self.gameProgress += 1
if self.gameProgress == 1 {
self.progressBar.progress = 1000.0
return
}
self.progressBar.progress = gameProgress
}
答案 0 :(得分:0)
你应该做的是将gameProgress除以1000,而不是尝试设置进度条的进度,而不是1/1000。这样做会返回一个可应用于进度条的分数,由于进度条的最小值为0.0,最大值为1.0