First you have to make all buttons background clear
func clearButtons() {
button1.backgroundColor = .clear
button2.backgroundColor = .clear
button3.backgroundColor = .clear
button4.backgroundColor = .clear
button5.backgroundColor = .clear
}
call this func in viewDidLoad
or viewWillAppear
Also make Ib-Action of all buttons
and call this method on every button Tapped IBAction forExample if button1 is pressed you have to do like this
@IBAction func Button1Tapped(_ sender: Any) {
clearButtons()
button1.backgroundColor = .white
}
same thing you have to do in all buttons action and change the button name which is pressed.
hope its help....
您可以创建一个包含 collectionView(作为组件)的单元格,将其设置为单选并覆盖 UICollectionViewCell 的 selected 方法以更改颜色和内容...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.