UIKit에서 라디오 버튼 만들기
UIKit 에는 라디오 버튼이 따로 없어서 직접 만들어야 한다.
@IBOutlet var radioButtons: [UIButton]!
Swift
복사
먼저 스토리보드로 연결을 시켜준 다음, 태그를 단다 (남 : 0, 여 : 1)
@objc private func radioButton(_ sender: UIButton) {
print("태그 번호 : ", sender.tag)
self.radioButtons.forEach {
if $0.tag == sender.tag {
$0.setImage(UIImage(systemName: "circle.fill"), for: .normal)
}
else {
$0.setImage(UIImage(systemName: "circle"), for: .normal)
}
}
}
Swift
복사
완성!