73 lines
2.6 KiB
Swift
73 lines
2.6 KiB
Swift
//
|
|
// CommonViewField.swift
|
|
// Wallet
|
|
//
|
|
// Created by Igor on 04.03.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class CommonViewField: CommonViewCustom {
|
|
@IBOutlet private var rightButton: UIButton!
|
|
@IBOutlet private weak var titleLbl: UILabel!
|
|
@IBOutlet private weak var textLbl: UILabel!
|
|
@IBOutlet private weak var marginConstraint: NSLayoutConstraint!
|
|
@IBInspectable var margin: CGFloat = 2 { didSet { marginConstraint.constant = margin } }
|
|
@IBInspectable var title: String? { didSet { updateTitle() } }
|
|
@IBInspectable var titleStyle: String = "regular_16" { didSet { updateTitle() } }
|
|
@IBInspectable var titleColor: UIColor = Asset.textCoal.color { didSet { updateTitle() } }
|
|
private func updateTitle() { titleLbl.attributedText = title?.localized.attributed(named: titleStyle, color: titleColor) }
|
|
@IBInspectable var text: String? { didSet { updateText() } }
|
|
@IBInspectable var textStyle: String = "bold_16" { didSet { updateText() } }
|
|
@IBInspectable var textColor: UIColor = Asset.textCoal.color { didSet { updateText() } }
|
|
private func updateText() { textLbl.attributedText = text?.localized.attributed(named: textStyle, color: textColor) }
|
|
|
|
@IBInspectable fileprivate var rightButtonAvailbale: Bool = false {
|
|
willSet {
|
|
self.rightButton.isHidden = !newValue
|
|
}
|
|
}
|
|
|
|
@IBInspectable fileprivate var rightButtonImage: UIImage = Asset.commonCopy.image {
|
|
willSet {
|
|
rightButton.setImage(newValue, for: .normal)
|
|
}
|
|
}
|
|
|
|
fileprivate var rightButtonAction: (() -> Void)?
|
|
|
|
@IBAction private func buttonDidTapInside(_ sender: Any) {
|
|
self.rightButtonAction?()
|
|
}
|
|
|
|
}
|
|
|
|
extension UIView {
|
|
static func field(
|
|
title: String? = nil,
|
|
titleStyle: String = "regular_16",
|
|
titleColor: UIColor = Asset.textCoal.color,
|
|
text: String? = nil,
|
|
textStyle: String = "bold_16",
|
|
textColor: UIColor = Asset.textCoal.color,
|
|
margin: CGFloat = 2,
|
|
rightButtonAvailbale: Bool? = false,
|
|
rightButtonImage: UIImage? = nil,
|
|
rightButtonAction: (() -> Void)? = nil
|
|
) -> CommonViewField {
|
|
let view = CommonViewField()
|
|
view.title = title
|
|
view.titleStyle = titleStyle
|
|
view.titleColor = titleColor
|
|
view.text = text
|
|
view.textStyle = textStyle
|
|
view.textColor = textColor
|
|
view.margin = margin
|
|
view.rightButtonAvailbale = rightButtonAvailbale ?? false
|
|
view.rightButtonImage = rightButtonImage ?? UIImage()
|
|
view.rightButtonAction = rightButtonAction
|
|
return view
|
|
}
|
|
}
|