Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在swift中的ui表格视图单元格上创建自定义单选按钮_Ios_Swift_Radio Button - Fatal编程技术网

Ios 如何在swift中的ui表格视图单元格上创建自定义单选按钮

Ios 如何在swift中的ui表格视图单元格上创建自定义单选按钮,ios,swift,radio-button,Ios,Swift,Radio Button,我需要在Swift的表格视图中创建自定义单选按钮,它在一个单元格中有两个以上的按钮。在一个单元格中,一次只能选择一个按钮 现在,我已经创建了多个按钮,其中选择了多个按钮。首先,您必须清除所有按钮的背景 func clearButtons() { button1.backgroundColor = .clear button2.backgroundColor = .clear button3.backgroundColor = .clear button4.backgroundColor

我需要在Swift的表格视图中创建自定义单选按钮,它在一个单元格中有两个以上的按钮。在一个单元格中,一次只能选择一个按钮


现在,我已经创建了多个按钮,其中选择了多个按钮。

首先,您必须清除所有按钮的背景

func clearButtons() {
 button1.backgroundColor = .clear
 button2.backgroundColor = .clear
 button3.backgroundColor = .clear
 button4.backgroundColor = .clear
 button5.backgroundColor = .clear
 }
viewDidLoad
viewwillbeen中调用此函数
同时,对所有按钮执行
Ib操作
,并对每个点击的按钮调用此方法。例如,如果按下按钮1,则必须这样做

 @IBAction func Button1Tapped(_ sender: Any) {
    clearButtons()
 button1.backgroundColor = .white
}
在所有按钮操作中都必须执行相同的操作,并更改按下的按钮名称


希望对您有所帮助……

您可以创建一个包含collectionView(作为组件)的单元格,将其设置为单选并覆盖UICollectionViewCell的选定方法以更改颜色和内容……

签出我的答案到目前为止您尝试了什么?显示一些代码,说明您试图获得的关于可能出错的具体反馈。