learn phase learn phase - 1 year ago 148
Swift Question

RadioButton in swift

I am new to swift and just embeded a SSRadioButtonsController in Xcode now I want this to be displayed with some text in a


I have done this but it doesn't work at all.

@IBAction func infoClicked(sender: UIButton) {
self.displayAlert("My Health Action Plan Detail", message: "A Health Action Plan is personal plan describing what you need to do to stay healthy. Using the plan can help you focus your health activities.")

var radioButtonController = SSRadioButtonsController()
var currentButton = radioButtonController.selectedButton()

I need to display some radio buttons with text alongside in alert view

Answer Source

As @matt said You cannot add interface a UIAlertView or UIAlertController. And you can add ssradion button to view like this.

        let radioButton = SSRadioButton(frame: CGRect(x: 0, y: 0, width: 100, height: 20 ))
        radioButton.circleRadius = 8
        radioButton.circleColor = UIColor.redColor()
       radioButton.setTitle("1", forState: .Normal)
        radioButton.setTitleColor(UIColor.blackColor(), forState: .Normal)

        let radioButton1 = SSRadioButton(frame: CGRect(x: 0, y: 0, width: 100, height: 20 ))
        radioButton1.circleRadius = 8
        radioButton1.circleColor = UIColor.redColor()
        radioButton1.setTitle("2", forState: .Normal)
        radioButton1.setTitleColor(UIColor.blackColor(), forState: .Normal)

 var radioButtonController = SSRadioButtonsController(buttons: radioButton, radioButton1)
 radioBtnController.delegate = self

add radiobutton to view


and if you want to detect which button is clicked you need to implement SSRadioButtonControllerDelegate method didSelectButton.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download