【问题标题】:unable to add SSRadioButtonsController radio button title from code无法从代码中添加 SSRadioButtonsController 单选按钮标题
【发布时间】: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)。感谢您对此进行调查。

标签: ios swift


【解决方案1】:

发现解决方案默认按钮标题是白色的,我把它改成了黑色,它工作正常

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 2016-01-13
    • 2013-04-21
    • 2014-05-14
    • 1970-01-01
    • 2012-09-26
    • 2020-10-01
    相关资源
    最近更新 更多