69 lines
1.8 KiB
Swift
69 lines
1.8 KiB
Swift
|
|
//
|
|||
|
|
// Create.swift
|
|||
|
|
// Crush
|
|||
|
|
//
|
|||
|
|
// Created by Leon on 2025/7/23.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
import SnapKit
|
|||
|
|
import UIKit
|
|||
|
|
|
|||
|
|
/// A button for incrementing or decrementing values, used in order placement or tipping amount/unit adjustments
|
|||
|
|
class InDecreaseButton: UIButton {
|
|||
|
|
// MARK: - Initialization
|
|||
|
|
|
|||
|
|
override init(frame: CGRect) {
|
|||
|
|
super.init(frame: frame)
|
|||
|
|
setupButton()
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
required init?(coder: NSCoder) {
|
|||
|
|
super.init(coder: coder)
|
|||
|
|
setupButton()
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private func setupButton() {
|
|||
|
|
isEnabled = true
|
|||
|
|
layer.cornerRadius = 8
|
|||
|
|
layer.masksToBounds = true
|
|||
|
|
|
|||
|
|
// Assuming a fixed size of 48x48 as per original code
|
|||
|
|
snp.makeConstraints { make in
|
|||
|
|
make.size.equalTo(CGSize(width: 48, height: 48))
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// MARK: - Public Methods
|
|||
|
|
|
|||
|
|
func setupIncreaseState() {
|
|||
|
|
// Assuming MWIconFont is a utility for generating icon images
|
|||
|
|
// IconCodeAdd is likely an enum or constant for the "+" icon
|
|||
|
|
let iconImage = MWIconFont.image(fromIcon: .add, size: CGSize(width: 20, height: 20), color: .white)
|
|||
|
|
setImage(iconImage, for: .normal)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func setupDecreaseState() {
|
|||
|
|
// Assuming IconCodeReduce is an enum or constant for the "−" icon
|
|||
|
|
let iconImage = MWIconFont.image(fromIcon: .reduce, size: CGSize(width: 20, height: 20), color: .white)
|
|||
|
|
setImage(iconImage, for: .normal)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// MARK: - Property Overrides
|
|||
|
|
|
|||
|
|
override var isEnabled: Bool {
|
|||
|
|
didSet {
|
|||
|
|
tintColor = isEnabled ? UIColor.text : UIColor.disable
|
|||
|
|
|
|||
|
|
backgroundColor = isEnabled ? UIColor.c.csen : UIColor.c.csed
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// MARK: - Placeholder Assumptions
|
|||
|
|
|
|||
|
|
// Assuming MWIconFont is a utility class for generating icon images
|
|||
|
|
enum InDecreaseIconCode {
|
|||
|
|
case add
|
|||
|
|
case reduce
|
|||
|
|
}
|