首页 > 解决方案 > 更改 IBOutletCollection 中 UIButton 的背景颜色

问题描述

我有 16 个按钮。我想在单击按钮时更改按钮的背景颜色。

这是我的代码:

@IBOutlet var buttons: [UIButton]!

@IBAction func button_Taped(_ sender: UIButton) {  

    }
}

单击按钮更改按钮的背景颜色时如何更改

标签: iosswiftbackground-coloriboutletiboutletcollection

解决方案


@IBOutlet var buttons: [UIButton]!

@IBAction func button_Taped(_ sender: UIButton) {  
sender.backgroundColor = // your desired color
    }
}

推荐阅读