77 lines
3.0 KiB
Swift
77 lines
3.0 KiB
Swift
//
|
|
// ResourceInfoItem.swift
|
|
// Wallet
|
|
//
|
|
// Created by grigori on 22.09.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
class ResourceInfoItemView: UIView {
|
|
|
|
private let resourcesViewChartDraw = ResourcesViewChartDrawV2()
|
|
private let percentLabel = UILabel()
|
|
private let titleLabel = UILabel()
|
|
private let leftSubtitleLabel = UILabel()
|
|
private let rightSubtitleLabel = UILabel()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
setupViews()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
|
|
setupViews()
|
|
}
|
|
|
|
private func setupViews() {
|
|
|
|
addSubview(resourcesViewChartDraw)
|
|
addSubview(percentLabel)
|
|
addSubview(titleLabel)
|
|
addSubview(leftSubtitleLabel)
|
|
addSubview(rightSubtitleLabel)
|
|
|
|
subviews.forEach( { $0.translatesAutoresizingMaskIntoConstraints = false })
|
|
|
|
UIView.activate(constraints: [
|
|
heightAnchor.constraint(equalToConstant: 80),
|
|
resourcesViewChartDraw.topAnchor.constraint(equalTo: topAnchor, constant: 12),
|
|
resourcesViewChartDraw.leftAnchor.constraint(equalTo: leftAnchor, constant: 15),
|
|
resourcesViewChartDraw.widthAnchor.constraint(equalToConstant: 54),
|
|
resourcesViewChartDraw.heightAnchor.constraint(equalToConstant: 54),
|
|
percentLabel.topAnchor.constraint(equalTo: topAnchor, constant: 30),
|
|
percentLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 27),
|
|
percentLabel.widthAnchor.constraint(equalToConstant: 32),
|
|
titleLabel.topAnchor.constraint(equalTo: topAnchor, constant: 20),
|
|
titleLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 86),
|
|
leftSubtitleLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 4),
|
|
leftSubtitleLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 86),
|
|
rightSubtitleLabel.topAnchor.constraint(equalTo: leftSubtitleLabel.topAnchor),
|
|
rightSubtitleLabel.leftAnchor.constraint(equalTo: leftSubtitleLabel.rightAnchor, constant: 4)
|
|
])
|
|
}
|
|
|
|
func update(progress: CGFloat, title: String, leftSubtitle: String, rightSubtitle: String) {
|
|
|
|
resourcesViewChartDraw.progress = progress
|
|
percentLabel.attributedText = "\(Int(progress*100))%".attributed(named: "regular_14")
|
|
titleLabel.attributedText = title.attributed(named: "regular_12")
|
|
leftSubtitleLabel.attributedText = leftSubtitle.attributed(named: "medium_16", color: Asset.textCoal.color)
|
|
rightSubtitleLabel.attributedText = rightSubtitle.attributed(named: "medium_16", color: Asset.textPebble.color)
|
|
percentLabel.textAlignment = .center
|
|
}
|
|
}
|
|
|
|
extension UIView {
|
|
static func activate(constraints: [NSLayoutConstraint]) {
|
|
constraints.forEach { ($0.firstItem as? UIView)?.translatesAutoresizingMaskIntoConstraints = false }
|
|
NSLayoutConstraint.activate(constraints)
|
|
}
|
|
}
|