118 lines
4.4 KiB
Swift
118 lines
4.4 KiB
Swift
//
|
|
// ResourcesItemContainerView.swift
|
|
// Wallet
|
|
//
|
|
// Created by grigori on 22.09.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
class ResourcesItemContainerView: UIView {
|
|
|
|
private let stackView = UIStackView()
|
|
|
|
private let leftButton = UIButton()
|
|
private let rightButton = UIButton()
|
|
|
|
private var leftButtonAction: (() -> Void)?
|
|
private var rightButtonAction: (() -> Void)?
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
setupViews()
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
setupViews()
|
|
}
|
|
|
|
private func setupViews() {
|
|
|
|
stackView.axis = .vertical
|
|
addSubview(stackView)
|
|
addSubview(leftButton)
|
|
addSubview(rightButton)
|
|
|
|
let hLine = UIView()
|
|
hLine.backgroundColor = Asset.marble.color
|
|
let vLine = UIView()
|
|
vLine.backgroundColor = Asset.marble.color
|
|
|
|
addSubview(hLine)
|
|
addSubview(vLine)
|
|
|
|
layer.cornerRadius = 16
|
|
|
|
UIView.activate(constraints: [
|
|
stackView.topAnchor.constraint(equalTo: topAnchor),
|
|
stackView.leftAnchor.constraint(equalTo: leftAnchor),
|
|
stackView.rightAnchor.constraint(equalTo: rightAnchor),
|
|
hLine.leftAnchor.constraint(equalTo: leftAnchor),
|
|
hLine.rightAnchor.constraint(equalTo: rightAnchor),
|
|
hLine.topAnchor.constraint(equalTo: stackView.bottomAnchor),
|
|
hLine.heightAnchor.constraint(equalToConstant: 1),
|
|
vLine.topAnchor.constraint(equalTo: hLine.bottomAnchor),
|
|
vLine.centerXAnchor.constraint(equalTo: centerXAnchor),
|
|
vLine.widthAnchor.constraint(equalToConstant: 1),
|
|
vLine.heightAnchor.constraint(equalToConstant: 49),
|
|
vLine.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
leftButton.heightAnchor.constraint(equalToConstant: 49),
|
|
rightButton.heightAnchor.constraint(equalToConstant: 49),
|
|
leftButton.widthAnchor.constraint(equalToConstant: (UIScreen.main.bounds.width - 25.0) / 2.0),
|
|
rightButton.widthAnchor.constraint(equalToConstant: (UIScreen.main.bounds.width - 25.0) / 2.0),
|
|
leftButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0),
|
|
leftButton.leftAnchor.constraint(equalTo: leftAnchor, constant: 0),
|
|
rightButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0),
|
|
rightButton.rightAnchor.constraint(equalTo: rightAnchor, constant: 0)
|
|
])
|
|
}
|
|
|
|
func update(models: [Resources.Model.Performance],
|
|
leftButtonTitle: String,
|
|
leftButtonAction: @escaping () -> Void,
|
|
rightButtonTitle: String,
|
|
rightButtonAction: @escaping ()-> Void) {
|
|
|
|
models.forEach { performance in
|
|
let view = ResourceInfoItemView()
|
|
view.update(progress: CGFloat(performance.availableProgress),
|
|
title: performance.kind.title,
|
|
leftSubtitle: performance.avaliableStr,
|
|
rightSubtitle: performance.maxStr)
|
|
stackView.addArrangedSubview(view)
|
|
stackView.setCustomSpacing(-10, after: view)
|
|
}
|
|
|
|
leftButton.setAttributedTitle(leftButtonTitle.attributed(named: "medium_14",
|
|
color: Asset.textDeepWater.color),
|
|
for: .normal)
|
|
rightButton.setAttributedTitle(rightButtonTitle.attributed(named: "medium_14",
|
|
color: Asset.textDeepWater.color),
|
|
for: .normal)
|
|
self.leftButtonAction = leftButtonAction
|
|
self.rightButtonAction = rightButtonAction
|
|
|
|
leftButton.addTarget(self, action: #selector(didTapLeftButton), for: .touchUpInside)
|
|
rightButton.addTarget(self, action: #selector(didTapRightButton), for: .touchUpInside)
|
|
|
|
makeShadow()
|
|
layoutIfNeeded()
|
|
}
|
|
|
|
func clear() {
|
|
stackView.arrangedSubviews.forEach({ $0.removeFromSuperview() })
|
|
}
|
|
|
|
@objc func didTapLeftButton() {
|
|
leftButtonAction?()
|
|
}
|
|
|
|
@objc func didTapRightButton() {
|
|
rightButtonAction?()
|
|
}
|
|
}
|