【发布时间】:2016-05-22 09:08:03
【问题描述】:
我正在使用 https://github.com/shamasshahid/SSRadioButtonsController 。当我通过情节提要添加单选按钮并设置标题时,它工作正常,但是当我尝试通过代码添加单选按钮的设置标题时,它不起作用。
类 ViewController: UIViewController, SSRadioButtonControllerDelegate {
var radioButtonController: SSRadioButtonsController?
覆盖 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)
}
}
【问题讨论】:
-
您的按钮圆角半径是否有效
-
是的,它工作正常。
-
更改按钮的框架并尝试一次...
-
frame 表示改变宽度,如将
20改为150 -
发现解决方案默认按钮标题为白色,我将其更改为 radioButton1.setTitleColor(UIColor.blackColor(), forState: .Normal)。感谢您对此进行调查。