An easy way to implement RadioButtons in Swift
- Create RadioButtons in iOS
- Customize the RadioButtons:
- Colors
- Width
- Optional Controller
- iOS 9+
- Swift 4+
pod 'GARRadioButton', '~> 1.0'
- Create an UIButton
- Go to Identity Inspector and set RadioButton as Class and GARRadioButton as Module
-
Set IBOutlets in the ViewController
-
ViewController
import UIKit
import GARRadioButton
class ViewController: UIViewController {
@IBOutlet weak var radioButtonOne: RadioButton!
@IBOutlet weak var radioButtonTwo: RadioButton!
var radioController: RadioButtonController!
override func viewDidLoad() {
super.viewDidLoad()
let arrRadioButtons: [RadioButton] = [radioButtonOne, radioButtonTwo]
radioController = RadioButtonController(arrRadioButton: arrRadioButtons)
}
}
extension ViewController: RadioButtonControllerDelegate {
func radioButton(_ radioButtonController: RadioButtonController, radioButton changed: RadioButton) {
}
}