Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
efb3e23d6c
commit
dee5de907d
@ -27,82 +27,87 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
@IBOutlet weak var showErrorSwitch: UISwitch!
|
@IBOutlet weak var showErrorSwitch: UISwitch!
|
||||||
@IBOutlet weak var errorTextField: UITextField!
|
@IBOutlet weak var errorTextField: UITextField!
|
||||||
|
|
||||||
var radioButton: RadioButton!
|
// var radioButton: RadioButton!
|
||||||
var radioButton2: RadioButton!
|
// var radioButton2: RadioButton!
|
||||||
|
var radioButtonGroup = RadioButtonGroup()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
var model = DefaultRadioButtonModel()
|
var model1 = DefaultRadioButtonModel()
|
||||||
model.labelText = "Terms and conditions"
|
model1.inputId = "model1"
|
||||||
model.childText = "I agree to Verizon's terms and conditions click here"
|
model1.labelText = "Terms and conditions"
|
||||||
model.childTextAttributes = [
|
model1.childText = "I agree to Verizon's terms and conditions click here"
|
||||||
|
model1.childTextAttributes = [
|
||||||
LabelAttributeUnderline(location: 11, length: 10),
|
LabelAttributeUnderline(location: 11, length: 10),
|
||||||
LabelAttributeStrikeThrough(location: 22, length: 5),
|
LabelAttributeStrikeThrough(location: 22, length: 5),
|
||||||
LabelAttributeColor(location: 31, length: 10, color: UIColor.blue.hexString!),
|
LabelAttributeColor(location: 31, length: 10, color: UIColor.blue.hexString!),
|
||||||
LabelAttributeActionModel(location: 31, length: 10){ print("clicked on the word 'conditions'") },
|
LabelAttributeActionModel(location: 31, length: 10){ print("clicked on the word 'conditions'") },
|
||||||
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!)
|
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!)
|
||||||
]
|
]
|
||||||
model.errorText = "Error Text"
|
model1.errorText = "Error Text"
|
||||||
|
|
||||||
var model2 = DefaultRadioButtonModel()
|
var model2 = DefaultRadioButtonModel()
|
||||||
|
model2.inputId = "model2"
|
||||||
model2.childText = "Radio Sample 2"
|
model2.childText = "Radio Sample 2"
|
||||||
|
|
||||||
|
|
||||||
surfaceLabel.text = model.surface.rawValue
|
surfaceLabel.text = model1.surface.rawValue
|
||||||
disabledSwitch.isOn = model.selected
|
disabledSwitch.isOn = model1.selected
|
||||||
labelTextField.text = model.labelText
|
labelTextField.text = model1.labelText
|
||||||
childTextField.text = model.childText
|
childTextField.text = model1.childText
|
||||||
showErrorSwitch.isOn = model.showError
|
showErrorSwitch.isOn = model1.showError
|
||||||
errorTextField.text = model.errorText
|
errorTextField.text = model1.errorText
|
||||||
|
|
||||||
radioButton = RadioButton(with: model)
|
// radioButton = RadioButton(with: model)
|
||||||
radioButton.translatesAutoresizingMaskIntoConstraints = false
|
// radioButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
//
|
||||||
|
// radioButton2 = RadioButton(with: model2)
|
||||||
|
// radioButton2.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
||||||
radioButton2 = RadioButton(with: model2)
|
// let radioButtonController = RadioButtonController()
|
||||||
radioButton2.translatesAutoresizingMaskIntoConstraints = false
|
// radioButton.selectorController = radioButtonController
|
||||||
|
// radioButton2.selectorController = radioButtonController
|
||||||
let radioButtonController = RadioButtonController()
|
|
||||||
radioButton.selectorController = radioButtonController
|
|
||||||
radioButton2.selectorController = radioButtonController
|
|
||||||
|
|
||||||
let stackView = UIStackView()
|
// let stackView = UIStackView()
|
||||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
// stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
stackView.axis = .vertical
|
// stackView.axis = .vertical
|
||||||
stackView.spacing = 10
|
// stackView.spacing = 10
|
||||||
stackView.addArrangedSubview(radioButton)
|
// stackView.addArrangedSubview(radioButton)
|
||||||
stackView.addArrangedSubview(radioButton2)
|
// stackView.addArrangedSubview(radioButton2)
|
||||||
|
radioButtonGroup.set(with: RadioButtonGroupModel(models: [model1, model2]))
|
||||||
componentContainerView.addSubview(stackView)
|
componentContainerView.addSubview(radioButtonGroup)
|
||||||
|
|
||||||
stackView.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
|
radioButtonGroup.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
|
||||||
stackView.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
|
radioButtonGroup.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
|
||||||
stackView.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
|
radioButtonGroup.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
|
||||||
stackView.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
|
radioButtonGroup.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
|
||||||
|
|
||||||
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
||||||
setupPicker()
|
setupPicker()
|
||||||
}
|
}
|
||||||
|
var radioButton: RadioButton? {
|
||||||
|
radioButtonGroup.radioButtons.first
|
||||||
|
}
|
||||||
@IBAction func disabledChanged(_ sender: UISwitch) {
|
@IBAction func disabledChanged(_ sender: UISwitch) {
|
||||||
radioButton.disabled = sender.isOn
|
radioButtonGroup.disabled = sender.isOn
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func onLabelTextDidEnd(_ sender: UITextField) {
|
@IBAction func onLabelTextDidEnd(_ sender: UITextField) {
|
||||||
radioButton.labelText = sender.text
|
radioButton?.labelText = sender.text
|
||||||
sender.resignFirstResponder()
|
sender.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func onChildTextDidEnd(_ sender: UITextField) {
|
@IBAction func onChildTextDidEnd(_ sender: UITextField) {
|
||||||
radioButton.childText = sender.text
|
radioButton?.childText = sender.text
|
||||||
sender.resignFirstResponder()
|
sender.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func showErrorChanged(_ sender: UISwitch) {
|
@IBAction func showErrorChanged(_ sender: UISwitch) {
|
||||||
radioButton.showError = sender.isOn
|
radioButton?.showError = sender.isOn
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
|
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
|
||||||
radioButton.errorText = sender.text
|
radioButton?.errorText = sender.text
|
||||||
sender.resignFirstResponder()
|
sender.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +138,7 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
func setupPicker(){
|
func setupPicker(){
|
||||||
picker.isHidden = true
|
picker.isHidden = true
|
||||||
surfacePicker.onPickerDidSelect = { item in
|
surfacePicker.onPickerDidSelect = { item in
|
||||||
self.radioButton.surface = item
|
self.radioButtonGroup.surface = item
|
||||||
self.componentContainerView.backgroundColor = item.color
|
self.componentContainerView.backgroundColor = item.color
|
||||||
self.surfaceLabel.text = item.rawValue
|
self.surfaceLabel.text = item.rawValue
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user