gpt4 book ai didi

ios - Swift 中的数组 - 如何添加图像

转载 作者:行者123 更新时间:2023-11-30 13:50:33 25 4
gpt4 key购买 nike

我正在制作一个应用程序,将分数保持在 1 到 20 之间,然后在分数 >= 21 时显示图像。但是我不知道如何解决这个问题,我有一个标签显示用户分数整数。有没有办法可以在 20 后将图像添加到数组中?或者有没有办法在分数 >= 21 时添加一个字符串,表示“Bullseye”字符串或图像。我只是不知道最好的方法有什么帮助吗?

import UIKit

class ViewController: UIViewController {
//Below are all of the labels at the top of AZG
@IBOutlet weak var user1name: UILabel!
@IBOutlet weak var user2name: UILabel!
@IBOutlet weak var lbl_currentPlayer: UILabel!
@IBOutlet weak var user1score: UILabel!
@IBOutlet weak var user2score: UILabel!



//Below are all the declared variables
var usernames = ["Big Meat ", "J Hooks "]
var currentPlayer = 0
var scores = [0,0]
var count = 0
var sdCount = 0

override func viewDidLoad() {
super.viewDidLoad()
setupGame()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func newGame() {
user1score.text = "\(count)"
user2score.text = "\(count)"
user1name.text = "\(usernames[0])"
user2name.text = "\(usernames[1])"
lbl_currentPlayer.text = usernames[currentPlayer]
scores = [0,0]
}

func setupGame() {
user1score.text = "\(count)"
user2score.text = "\(count)"
user1name.text = "\(usernames[0])"
user2name.text = "\(usernames[1])"
lbl_currentPlayer.text = usernames[currentPlayer]
}

func updateTurn() {
lbl_currentPlayer.text = usernames[currentPlayer]
user1score.text = "\(scores[0])"
user2score.text = "\(scores[1])"
}

func attackTurnUpdate() {
currentPlayer = 1 - currentPlayer
}

func resetAttackTurn() {
currentPlayer = 1 - currentPlayer
}

func missedNextTurn() {
currentPlayer = 1 - currentPlayer
}

func suddenDeath() {
sdCount = sdCount++
}

func takeStepBack() {
}

func bullseyeDisplay() {

}

@IBAction func hitSingle(sender: AnyObject) {
scores[currentPlayer]++
updateTurn()
}

@IBAction func nextTurn(sender: AnyObject) {
currentPlayer = 1 - currentPlayer
updateTurn()
}

最佳答案

只需将图像添加到界面构建器中的 View (在代码中使用适当的 IBOutlet)并在其上设置“隐藏”即可。

然后当你想显示图片时,只需更改hidden的值即可:

my image.hidden = false

关于ios - Swift 中的数组 - 如何添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34341015/

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