Sahil Beri Sahil Beri - 3 months ago 47
Swift Question

unable to add SSRadioButtonsController radio button title from code

i'm using https://github.com/shamasshahid/SSRadioButtonsController . when i add radio buttons through storyboard and set titles it works fine but when i try to add set title of radio button through code it doesn't work.

class ViewController: UIViewController, SSRadioButtonControllerDelegate {

var radioButtonController: SSRadioButtonsController?

override func viewDidLoad() {
super.viewDidLoad()

var buttonArray = [UIButton]()


let radioButton = SSRadioButton(frame: CGRect(x: 20, y: 20, width: 20, height: 20 ))
radioButton.circleRadius = 8
radioButton.setTitle("male", forState: .Normal)

let radioButton1 = SSRadioButton(frame: CGRect(x: 20, y: 60, width: 20, height: 20 ))
radioButton.circleRadius = 8
radioButton.setTitle("female", forState: .Highlighted)

self.view.addSubview(radioButton)
self.view.addSubview(radioButton1)

buttonArray.append(radioButton)
buttonArray.append(radioButton1)

radioButtonController = SSRadioButtonsController(buttons: buttonArray)
radioButtonController!.delegate = self
radioButtonController!.shouldLetDeSelect = true

// Do any additional setup after loading the view, typically from a nib.
}

func didSelectButton(aButton: UIButton?) {
print(aButton)
}


}

Answer

Found the solution by default button title was white i changed it with black and it is working fine

radioButton1.setTitleColor(UIColor.blackColor(), forState: .Normal)