【发布时间】:2017-07-18 06:34:10
【问题描述】:
下面是我的代码。我的视图中有 9 个按钮要更改其背景图像。
import UIKit
class ViewController: UIViewController {
let alerts = UIAlertController(title: "Hi", message: "Hello", preferredStyle: UIAlertControllerStyle.alert)
let action1 = UIAlertAction(title: "Yes", style: UIAlertActionStyle.default) { (<#UIAlertAction#>) in
for i in 0..<9
{
let newButton = self.view.viewWithTag(i) as! UIButton
newButton.setBackgroundImage(UIImage.init(named: ""), for: .normal)
}
}
@IBAction func buttonPressed(_ sender: UIButton)
{
sender.setBackgroundImage(UIImage.init(named: "cross.png"), for:.normal)
}
}
【问题讨论】:
-
你在哪里添加这 9 个按钮?
-
有什么错误?是什么线导致它们?请edit您的问题提供这些详细信息。
-
我正在尝试访问下面代码中的按钮.. 让 newButton = self.view.viewWithTag(i) as! UIButton newButton.setBackgroundImage(UIImage.init(named: ""), for: .normal)
-
你想做什么,你面临的问题是什么?还是不清楚你的问题
-
你是在 xib 还是 storyboard 中添加按钮?