gpt4 book ai didi

ios - 需要用按钮 Swift 生成的 Int 更改 UIImageView

转载 作者:行者123 更新时间:2023-11-28 06:16:29 24 4
gpt4 key购买 nike

我正在开发一个可以控制气候的应用程序。值发生变化,但是,我无法根据值显示不同的 (Guage) 图像。请帮忙!

这是我的代码

 /* Fan Output Up */

@IBAction func FanOutputUpBtn(_ sender: Any) {

let name = "Fan Position\(fanCounter)"
/* Setting the name of the fan position image including the variable fanCounter */

fanPositionImage.image = UIImage(named: "fanPosition \(fanCounter)")
/* Setting the name of the fan position image including the variable fanCounter */

if fanCounter == 5 {
/* Set maximum value */
} else {

fanCounter += 1
/* Increase the fan counter position by 1 */

TestFanCounter.text = String(Int(self.fanCounter))
/* Display the counter image */

self.fanPositionImage.image = UIImage(named: name)
/* Display image for fan position based on fan counter */


}

更新

现在它是随机显示的图像,但是 TestFanCounter.text = String(Int(self.fanCounter)) 显示完全正常

   /* Fan Output Up */

@IBAction func FanOutputUpBtn(_ sender: Any) {

let name = "Fan Position \(fanCounter)"
// Setting the name of the fan position image including the variable fanCounter

if fanCounter == 4 {
// Set maximum value
} else {

fanCounter += 1
// Increase the fan counter position by 1

TestFanCounter.text = String(Int(self.fanCounter))
// Display the counter image

self.fanPositionImage.image = UIImage(named: name)
/* Display image for fan position based on fan counter */

}

最佳答案

您在设置名称后递增 fanCounter。当您显示计数器时,它会比您分配名称时高一个,您将使用该名称来设置图像。这些值应该相等吗?

关于ios - 需要用按钮 Swift 生成的 Int 更改 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44980622/

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