From f2b426df9aa97c040bc3a579d78f8894e7ad1c46 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 2 Aug 2022 15:09:46 -0500 Subject: [PATCH] added checkbox vc Signed-off-by: Matt Bruce --- VDSSample.xcodeproj/project.pbxproj | 4 + VDSSample/Resources/Components.storyboard | 185 +++++++++++++++++- .../CheckboxViewController.swift | 95 +++++++++ .../ViewControllers/MenuViewController.swift | 5 +- .../ToggleViewController.swift | 2 +- 5 files changed, 288 insertions(+), 3 deletions(-) create mode 100644 VDSSample/ViewControllers/CheckboxViewController.swift diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index 0b3a4a0..57d539f 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ EA3C3BC5289968B1000CA526 /* VDS.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BC3289968B1000CA526 /* VDS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; EAF7F07C2899698800B287F5 /* Components.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EAF7F07A2899698800B287F5 /* Components.storyboard */; }; EAF7F07D2899698800B287F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAF7F07B2899698800B287F5 /* Assets.xcassets */; }; + EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -61,6 +62,7 @@ EA3C3BC3289968B1000CA526 /* VDS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = VDS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EAF7F07A2899698800B287F5 /* Components.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Components.storyboard; sourceTree = ""; }; EAF7F07B2899698800B287F5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -144,6 +146,7 @@ children = ( EA3C3BB228996775000CA526 /* MenuViewController.swift */, EA3C3BB328996775000CA526 /* ToggleViewController.swift */, + EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -227,6 +230,7 @@ EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */, EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */, EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */, + EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/VDSSample/Resources/Components.storyboard b/VDSSample/Resources/Components.storyboard index 0580a03..92cd019 100644 --- a/VDSSample/Resources/Components.storyboard +++ b/VDSSample/Resources/Components.storyboard @@ -279,7 +279,190 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VDSSample/ViewControllers/CheckboxViewController.swift b/VDSSample/ViewControllers/CheckboxViewController.swift new file mode 100644 index 0000000..6bcacfc --- /dev/null +++ b/VDSSample/ViewControllers/CheckboxViewController.swift @@ -0,0 +1,95 @@ +// +// CheckboxViewController.swift +// VDSSample +// +// Created by Matt Bruce on 8/1/22. +// + +import Foundation +import UIKit +import VDS +import VDSColorTokens + +class CheckboxViewController: UIViewController, StoryboardInitable { + enum PickerType { + case surface + } + static var storyboardId: String = "checkbox" + static var storyboardName: String = "Components" + + @IBOutlet weak var checkboxContainerView: UIView! + @IBOutlet weak var picker: UIPickerView! + @IBOutlet weak var surfaceLabel: UILabel! + + var checkbox: VDSCheckbox! + + override func viewDidLoad() { + super.viewDidLoad() + + checkbox = VDSCheckbox() + checkbox.translatesAutoresizingMaskIntoConstraints = false + checkboxContainerView.addSubview(checkbox) + checkbox.leadingAnchor.constraint(equalTo: checkboxContainerView.leadingAnchor, constant: 20).isActive = true + checkbox.bottomAnchor.constraint(equalTo: checkboxContainerView.bottomAnchor, constant: -20).isActive = true + checkbox.topAnchor.constraint(equalTo: checkboxContainerView.topAnchor, constant: 20).isActive = true + view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:)))) + setupPicker() + } + + @IBAction func disabledChanged(_ sender: UISwitch) { + checkbox.disabled = sender.isOn + } + + @IBAction func onLabelTextDidEnd(_ sender: UITextField) { + checkbox.labelText = sender.text + sender.resignFirstResponder() + } + + @IBAction func onChildTextDidEnd(_ sender: UITextField) { + checkbox.childText = sender.text + sender.resignFirstResponder() + } + + @IBAction func showErrorChanged(_ sender: UISwitch) { + checkbox.disabled = sender.isOn + } + + @IBAction func onErrorTextDidEnd(_ sender: UITextField) { + checkbox.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.checkbox.surface = item + self.checkboxContainerView.backgroundColor = item.color + self.surfaceLabel.text = item.rawValue + } + } +} + diff --git a/VDSSample/ViewControllers/MenuViewController.swift b/VDSSample/ViewControllers/MenuViewController.swift index e7a2253..cb065d0 100644 --- a/VDSSample/ViewControllers/MenuViewController.swift +++ b/VDSSample/ViewControllers/MenuViewController.swift @@ -14,7 +14,10 @@ struct MenuComponent { } class MenuViewController: UITableViewController { - let items: [MenuComponent] = [MenuComponent(title: "Toggle", viewController: ToggleViewController.self)] + let items: [MenuComponent] = [ + MenuComponent(title: "Toggle", viewController: ToggleViewController.self), + MenuComponent(title: "Checkbox", viewController: CheckboxViewController.self) + ] override func numberOfSections(in tableView: UITableView) -> Int { 1 diff --git a/VDSSample/ViewControllers/ToggleViewController.swift b/VDSSample/ViewControllers/ToggleViewController.swift index c793f3b..46ed082 100644 --- a/VDSSample/ViewControllers/ToggleViewController.swift +++ b/VDSSample/ViewControllers/ToggleViewController.swift @@ -14,7 +14,7 @@ class ToggleViewController: UIViewController, StoryboardInitable { enum PickerType { case surface, textSize, textPosition, fontWeight } - static var storyboardId: String = "toggle" + static var storyboardId: String = "checkbox" static var storyboardName: String = "Components" @IBOutlet weak var toggleContainerView: UIView!