我们为所有按钮提供了一种通用操作,并为这些标签提供了 0、1、2 等标签。
试试这个代码。
@IBAction func radioButtonAction(_ sender: UIButton) {
weeklybtn.setImage(UIImage(named: "Radio Button"), for: .normal)
biweeklybtn.setImage(UIImage(named: "Radio Button"), for: .normal)
nothisonlybtn.setImage(UIImage(named: "Radio Button"), for: .normal)
weeklylbl.textColor = UIColor(red: 92/255, green: 112/255, blue: 139/255, alpha: 1.0)
biweeklylbl.textColor = UIColor(red: 92/225, green: 112/255, blue: 139/255, alpha: 1.0)
onlyForthisLbl.textColor = UIColor(red: 92/225, green: 112/255, blue: 139/255, alpha: 1.0)
if sender.tag == 0
{
weeklybtn.setImage(UIImage(named: "Checked"), for: .normal)
weeklylbl.textColor = UIColor(red: 46/225, green: 125/255, blue: 225/255, alpha: 1.0)
}
else if sender.tag == 1
{
biweeklybtn.setImage(UIImage(named: "Checked"), for: .normal)
biweeklylbl.textColor = UIColor(red: 46/225, green: 125/255, blue: 225/255, alpha: 1.0)
}
else
{
nothisonlybtn.setImage(UIImage(named: "Checked"), for: .normal)
onlyForthisLbl.textColor = UIColor(red: 46/225, green: 125/255, blue: 225/255, alpha: 1.0)
}
}