117 lines
3.1 KiB
Swift
117 lines
3.1 KiB
Swift
//
|
|
// ButtonIcon.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 5/12/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
@objc(VDSButtonIcon)
|
|
open class ButtonIcon: Control {
|
|
//--------------------------------------------------
|
|
// MARK: - Models
|
|
//--------------------------------------------------
|
|
//--------------------------------------------------
|
|
// MARK: - Enums
|
|
//--------------------------------------------------
|
|
public enum Kind: String, CaseIterable {
|
|
case ghost, lowContrast, highContrast
|
|
}
|
|
|
|
public enum SurfaceType: String, CaseIterable {
|
|
case colorFill, media
|
|
}
|
|
|
|
public enum Size: String, EnumSubset {
|
|
case large
|
|
case small
|
|
|
|
public var defaultValue: Icon.Size { .large }
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Private Properties
|
|
//--------------------------------------------------
|
|
private var widthConstraint: NSLayoutConstraint?
|
|
private var heightConstraint: NSLayoutConstraint?
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Public Properties
|
|
//--------------------------------------------------
|
|
open var icon = Icon()
|
|
|
|
open var iconName: Icon.Name? { didSet { setNeedsUpdate() } }
|
|
|
|
open var kind: Kind = .ghost { didSet { setNeedsUpdate() } }
|
|
|
|
open var surfaceType: SurfaceType = .colorFill { didSet { setNeedsUpdate() } }
|
|
|
|
open var size: Size = .large { didSet { setNeedsUpdate() } }
|
|
|
|
open var floating: Bool = false { didSet { setNeedsUpdate() } }
|
|
|
|
open var hideBorder: Bool = true { didSet { setNeedsUpdate() } }
|
|
|
|
open var iconOffset: CGPoint? { didSet { setNeedsUpdate() } }
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Configuration
|
|
//--------------------------------------------------
|
|
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Initializers
|
|
//--------------------------------------------------
|
|
required public init() {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public override init(frame: CGRect) {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Lifecycle
|
|
//--------------------------------------------------
|
|
|
|
open override func setup() {
|
|
super.setup()
|
|
|
|
}
|
|
|
|
open override func reset() {
|
|
super.reset()
|
|
shouldUpdateView = false
|
|
kind = .ghost
|
|
surfaceType = .colorFill
|
|
size = .large
|
|
floating = false
|
|
hideBorder = true
|
|
iconOffset = nil
|
|
iconName = nil
|
|
shouldUpdateView = true
|
|
setNeedsUpdate()
|
|
}
|
|
|
|
open override func updateView() {
|
|
super.updateView()
|
|
|
|
if let iconName {
|
|
icon.name = iconName
|
|
icon.size = size.value
|
|
icon.surface = surface
|
|
icon.disabled = disabled
|
|
} else {
|
|
icon.reset()
|
|
}
|
|
|
|
}
|
|
|
|
}
|