vds_ios_sample/VDSSample/ViewControllers/RadioButtonViewController.swift
Matt Bruce 3b0a453aab update for VDS changes
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-08 10:46:53 -05:00

121 lines
4.3 KiB
Swift

//
// RadioButtonViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/1/22.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
class RadioButtonViewController: UIViewController, StoryboardInitable {
enum PickerType {
case surface
}
static var storyboardId: String = "radioButton"
static var storyboardName: String = "Components"
@IBOutlet weak var componentContainerView: UIView!
@IBOutlet weak var picker: UIPickerView!
@IBOutlet weak var surfaceLabel: UILabel!
@IBOutlet weak var disabledSwitch: UISwitch!
@IBOutlet weak var labelTextField: UITextField!
@IBOutlet weak var childTextField: UITextField!
@IBOutlet weak var showErrorSwitch: UISwitch!
@IBOutlet weak var errorTextField: UITextField!
var radioButton: RadioButton!
override func viewDidLoad() {
super.viewDidLoad()
var model = DefaultRadioButtonModel()
model.labelText = "Terms and conditions"
model.childText = "I agree to Verizon's terms and conditions click here"
model.childTextAttributes = [
LabelAttributeUnderline(location: 11, length: 10),
LabelAttributeStrikeThrough(location: 22, length: 5),
LabelAttributeColor(location: 31, length: 10, color: UIColor.blue.hexString!),
LabelAttributeActionModel(location: 31, length: 10){ print("clicked on the word 'conditions'") },
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!)
]
model.errorText = "Error Text"
surfaceLabel.text = model.surface.rawValue
disabledSwitch.isOn = model.selected
labelTextField.text = model.labelText
childTextField.text = model.childText
showErrorSwitch.isOn = model.showError
errorTextField.text = model.errorText
radioButton = RadioButton(with: model)
radioButton.translatesAutoresizingMaskIntoConstraints = false
componentContainerView.addSubview(radioButton)
radioButton.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
radioButton.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
radioButton.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
radioButton.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
setupPicker()
}
@IBAction func disabledChanged(_ sender: UISwitch) {
radioButton.disabled = sender.isOn
}
@IBAction func onLabelTextDidEnd(_ sender: UITextField) {
radioButton.labelText = sender.text
sender.resignFirstResponder()
}
@IBAction func onChildTextDidEnd(_ sender: UITextField) {
radioButton.childText = sender.text
sender.resignFirstResponder()
}
@IBAction func showErrorChanged(_ sender: UISwitch) {
radioButton.showError = sender.isOn
}
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
radioButton.errorText = sender.text
sender.resignFirstResponder()
}
@IBAction func surfaceClick(_ sender: Any) {
pickerType = .surface
}
//Picker
var surfacePicker = SurfacePicker()
var pickerType: PickerType = .surface {
didSet {
func update(object: UIPickerViewDelegate & UIPickerViewDataSource){
picker.delegate = object
picker.dataSource = object
}
switch pickerType{
case .surface:
update(object: surfacePicker)
}
picker.reloadAllComponents()
picker.selectRow(0, inComponent: 0, animated: false)
picker.isHidden = false
}
}
func setupPicker(){
picker.isHidden = true
surfacePicker.onPickerDidSelect = { item in
self.radioButton.surface = item
self.componentContainerView.backgroundColor = item.color
self.surfaceLabel.text = item.rawValue
}
}
}