vds_ios_sample/VDSSample/Classes/Helper.swift
Matt Bruce 26bd70c5e8 fixed bug, refactored code
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-11-18 14:26:15 -06:00

73 lines
3.0 KiB
Swift

//
// Helper.swift
// VDSSample
//
// Created by Matt Bruce on 11/18/22.
//
import Foundation
import VDS
import UIKit
extension UIView {
public static func makeWrapper(for view: UIView) -> UIView {
let wrapper = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
wrapper.addSubview(view)
view
.pinTop()
.pinBottom()
.pinLeading()
view.trailingAnchor.constraint(lessThanOrEqualTo: wrapper.trailingAnchor).isActive = true
return wrapper
}
}
extension BaseViewController {
func makeButton(_ text: String) -> Button {
return Button().with{
$0.text = text
$0.publisher(for: .touchUpInside)
.sink { [weak self] control in
let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "\(control.text!) Clicked",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("clicked me")
}.store(in: &subscribers)
}
}
func makeTextLink(_ text: String) -> TextLink {
return TextLink().with{
$0.text = text
$0.publisher(for: .touchUpInside)
.sink { [weak self] control in
let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "\(control.text!) Clicked",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("clicked me")
}.store(in: &subscribers)
}
}
func makeTextLinkCaret(_ text: String) -> TextLinkCaret {
return TextLinkCaret().with{
$0.text = text
$0.publisher(for: .touchUpInside)
.sink { [weak self] control in
let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "\(control.text!) Clicked",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("clicked me")
}.store(in: &subscribers)
}
}
}