DavydLiu / DLRadioButton

Radio Button for iOS
MIT License
948 stars 202 forks source link

get value of selected radio button #130

Open d33pak-s1ngh opened 6 years ago

d33pak-s1ngh commented 6 years ago

Hello @DavydLiu thank you for this awesome DLRadioButton

i have a rating object array from which i am creating DLRadioButtons at runtime, a rating object have id and rating properties where i am using objects rating property as a label of DLRadioButton and i want to set id as a value of DLRadioButton, so that when user will select any radio button then its id will be passed on server how i can achieve this thing? please help. following is my code to loop through object array and create radio buttons

`for  rating in self.ratingList{
                            let radioButton = DLRadioButton()
                            radioButton.contentHorizontalAlignment = .left
                            radioButton.translatesAutoresizingMaskIntoConstraints = false
                            radioButton.titleLabel?.autoresizingMask = UIViewAutoresizing.flexibleWidth
                            radioButton.titleLabel!.font = UIFont.systemFont(ofSize: 14);
                            radioButton.setTitle(rating.rating, for: []);
                            radioButton.setTitleColor(UIColor.lightGray, for: [])
                            radioButton.iconColor = UIColor.black;
                            radioButton.indicatorColor = UIColor.black;
                            //radioButton.setValue(rating.ratingId, forKey: rating.ratingUniqueName!)
                            radioButton.addTarget(self, action: #selector(self.handleRating), for: UIControlEvents.touchUpInside);
                            self.ratingRadioButtons.append(radioButton)
                        }`

thank you in advance for suggestions.