以下是我的代碼。我的視圖中有9個按鈕,其背景圖像將被更改。奧瑞克幫助我。我intrested從外部方法訪問uibutton方法,但我得到很多錯誤
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個按鍵? – Venkat
有什麼錯誤?什麼線路導致他們?請用這些細節編輯你的問題。 – rmaddy
我想要訪問波紋管代碼中的按鈕..讓newButton = self.view.viewWithTag(i)as! UIButton newButton.setBackgroundImage(UIImage.init(named:「」),for:.normal) –