我正在创建一个可以控制气候的应用程序。值改变了,但是我无法根据值显示不同的(标尺)图像。请帮忙!

这是我的代码

 /* 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/

10-08 20:40