【发布时间】:2017-07-07 22:38:14
【问题描述】:
我正在创建一个可以控制气候的应用。值会发生变化,但是,我无法根据值显示不同的(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 */
}
}
【问题讨论】:
-
你在这里设置了两次相同的图像,这是故意的吗?在第一次和第二次分配之间,图像的命名架构也会发生变化。
-
嗨大卫,我明白了,我现在已经改变了这个,但它完全随机化了显示的图像
标签: ios swift button uiimageview counter