93 lines
2.7 KiB
Swift
93 lines
2.7 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, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> UIView {
|
|
return makeWrappedView(for: view, edgeSpacing: edgeSpacing, isTrailing: isTrailing).view
|
|
}
|
|
|
|
public class WrappedViewHelper {
|
|
public var view: UIView
|
|
|
|
var viewPadding: CGFloat = 0 {
|
|
didSet {
|
|
view._topConstraint?.constant = viewPadding
|
|
view._leadingConstraint?.constant = viewPadding
|
|
view._trailingConstraint?.constant = -viewPadding
|
|
view._bottomConstraint?.constant = -viewPadding
|
|
}
|
|
}
|
|
|
|
public init(view: UIView) {
|
|
self.view = view
|
|
}
|
|
}
|
|
|
|
public static func makeWrappedView(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> WrappedViewHelper {
|
|
let wrapper = UIView().with {
|
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
|
}
|
|
wrapper.addSubview(view)
|
|
|
|
view.pinTop(wrapper.topAnchor, edgeSpacing)
|
|
view.pinBottom(wrapper.bottomAnchor, edgeSpacing)
|
|
view.pinLeading(wrapper.leadingAnchor, edgeSpacing)
|
|
|
|
if isTrailing {
|
|
view.pinTrailingLessThanOrEqualTo(wrapper.trailingAnchor, edgeSpacing)
|
|
} else {
|
|
view.pinTrailing(wrapper.trailingAnchor, edgeSpacing)
|
|
}
|
|
return WrappedViewHelper(view: wrapper)
|
|
}
|
|
}
|
|
|
|
extension ButtonBase {
|
|
func labelPublisher(_ label: UILabel){
|
|
onClick = { control in
|
|
let newText = "\(control.text!) clicked - "
|
|
if let labelText = label.text {
|
|
let components = labelText.components(separatedBy: " - ")
|
|
let last: String = (components.last ?? "0").trimmingCharacters(in: .whitespaces)
|
|
let count = Int(last)!
|
|
label.text = "\(newText)\(count+1)"
|
|
} else {
|
|
label.text = "\(newText)1"
|
|
}
|
|
print("clicked me")
|
|
}
|
|
}
|
|
}
|
|
|
|
extension BaseViewController {
|
|
func makeButton(_ text: String, label: UILabel) -> Button {
|
|
return Button().with{
|
|
$0.text = text
|
|
$0.labelPublisher(label)
|
|
}
|
|
}
|
|
|
|
func makeTextLink(_ text: String, label: UILabel) -> TextLink {
|
|
return TextLink().with{
|
|
$0.text = text
|
|
$0.labelPublisher(label)
|
|
}
|
|
}
|
|
|
|
func makeTextLinkCaret(_ text: String, label: UILabel) -> TextLinkCaret {
|
|
return TextLinkCaret().with{
|
|
$0.text = text
|
|
$0.labelPublisher(label)
|
|
}
|
|
}
|
|
}
|