当我点击五个按钮时,我想要做的就是改变五个按钮和十个按钮的backgroundColor
。为什么这个代码不工作? @IBAction
也不起作用。如何在单击button1时快速更改button2的颜色?
@IBOutlet weak var fiveMinButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
fiveMinButton.addTarget(self, action: Selector(("action:")), for: UIControlEvents.touchUpInside)
func action(sender: UIButton){
if sender === fiveMinButton {
fiveMinButton.backgroundColor = UIColor.gray
tenMinButton.backgroundColor = UIColor.lightgray
}
}
'fiveMinButton.addTarget(self,action:#selector(action(sender :)),for:UIControlEvents.touchUpInside)'是正确的语法。修复了我的解决方案 – grant
欢迎队友:) –
第3点不正确。使用'==='是正确的,因为检查是看'sender'和'FiveMinButton'是否是相同的引用。 – rmaddy