learn phase learn phase - 24 days ago 10
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

UIAlertView
.

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()
radioButtonController.setButtonsArray([button1!,button2!,button3!])
var currentButton = radioButtonController.selectedButton()
}


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

Answer

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

self.view.addSubView(radioButton)
self.view.addSubView(radioButton1)

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