【发布时间】:2019-01-05 00:48:15
【问题描述】:
所以我有 3 个按钮
override func viewDidLoad() {
super.viewDidLoad()
weeklyRadioButton.setImage(UIImage(named: "a"), for: .normal)
weeklyRadioButton.setImage(UIImage(named: "b"), for: .selected)
biWeeklyRadioButton.setImage(UIImage(named: "a"), for: .normal)
biWeeklyRadioButton.setImage(UIImage(named: "b"), for: .selected)
noThanksRadioButton.setImage(UIImage(named: "a"), for: .normal)
noThanksRadioButton.setImage(UIImage(named: "b"), for: .selected)
}
@IBAction func biWeeklyRadioButtonTapped(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
weeklyRadioButton.setImage(UIImage(named: "a"), for: .normal) .
// its not changing then image of the button.
noThanksRadioButton.setImage(UIImage(named: "a"), for: .normal)
}
以及其他两个按钮的类似两个操作。
当前代码允许多选按钮。 我想知道在按钮中实现单选的方法。
假设我选择了按钮 1 在选择按钮 2 时,按钮 1 被取消选择
【问题讨论】:
-
是否可以添加额外的代码
标签: ios swift radio-button