89 lines
2.2 KiB
Swift
89 lines
2.2 KiB
Swift
//
|
|
// CommonViewInfoLabel.swift
|
|
// Wallet
|
|
//
|
|
// Created by Saveliy Stavitsky on 3/2/21.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@IBDesignable class CommonViewInfoLabel: CommonViewCustom {
|
|
|
|
@IBOutlet private weak var titleLbl: UILabel!
|
|
@IBOutlet private var textsStackView: UIStackView!
|
|
|
|
@IBInspectable public var lzTitle: String? {
|
|
get { titleLbl.text }
|
|
set {
|
|
titleLbl.text = newValue?.localized
|
|
}
|
|
}
|
|
|
|
func clearAll() {
|
|
textsStackView.arrangedSubviews
|
|
.forEach({ $0.removeFromSuperview() })
|
|
}
|
|
|
|
func clearTexts() {
|
|
textsStackView.arrangedSubviews
|
|
.filter({ $0.tag == 1 })
|
|
.forEach({ $0.removeFromSuperview() })
|
|
}
|
|
|
|
func clearErrors() {
|
|
textsStackView.arrangedSubviews
|
|
.filter({ $0.tag == 2 })
|
|
.forEach({ $0.removeFromSuperview() })
|
|
}
|
|
|
|
func addAttributedText(_ text: NSAttributedString) {
|
|
let label = UILabel()
|
|
label.backgroundColor = .clear
|
|
label.numberOfLines = 0
|
|
label.tag = 1
|
|
label.textAlignment = .left
|
|
label.attributedText = text
|
|
textsStackView.addArrangedSubview(label)
|
|
}
|
|
|
|
func addText(_ text: String) {
|
|
let label = UILabel()
|
|
label.backgroundColor = .clear
|
|
label.numberOfLines = 0
|
|
label.tag = 1
|
|
label.font = Font.font(style: .bold, size: 16)
|
|
label.textAlignment = .left
|
|
label.textColor = Asset.textCoal.color
|
|
label.text = text
|
|
textsStackView.addArrangedSubview(label)
|
|
}
|
|
|
|
func addError(_ error: String) {
|
|
let label = UILabel()
|
|
label.backgroundColor = .clear
|
|
label.numberOfLines = 0
|
|
label.tag = 2
|
|
label.font = Font.font(style: .regular, size: 12)
|
|
label.textAlignment = .left
|
|
label.textColor = Asset.textBrick.color
|
|
label.text = error
|
|
textsStackView.addArrangedSubview(label)
|
|
}
|
|
|
|
func updateAttributedText(_ text: NSAttributedString) {
|
|
clearTexts()
|
|
addAttributedText(text)
|
|
}
|
|
|
|
func updateText(_ text: String) {
|
|
clearTexts()
|
|
addText(text)
|
|
}
|
|
|
|
func updateError(_ error: String) {
|
|
clearErrors()
|
|
addError(error)
|
|
}
|
|
}
|