简体   繁体   中英

how to create custom radio button on ui table view cell in swift

在此处输入图片说明

I need to create custom radio button`s in table view in Swift which would be more than 2 buttons in 1 cell. It would let only 1 button be selected at a time in one cell.

Now I have created buttons where more than 1 button are selected.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM