// // SettingMultivaluesTableViewCell.swift // Earthquake Network // // Created by Busi Andrea on 26/08/2020. // Copyright © 2020 Earthquake Network. All rights reserved. // import Foundation class SettingMultivaluesTableViewCell: UITableViewCell { @objc static let Identifier = "MultivaluesCell" private static let ValueColor = UIColor.blue private static let TextColor = UIColor.black @objc var isDisabled: Bool = false { didSet { updateUI() } } // MARK: - Properties @objc lazy var titleLabel: UILabel = { let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false label.numberOfLines = 0 label.font = UIFont.preferredFont(forTextStyle: .body) return label }() @objc lazy var valuesLabel: UILabel = { let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false label.numberOfLines = 0 label.font = UIFont.preferredFont(forTextStyle: .subheadline) label.textColor = Self.ValueColor return label }() // MARK: - Init override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) setupUI() } required init?(coder: NSCoder) { super.init(coder: coder) setupUI() } // MARK: - Private private func setupUI() { translatesAutoresizingMaskIntoConstraints = false let stackView = UIStackView() stackView.translatesAutoresizingMaskIntoConstraints = false stackView.axis = .vertical stackView.distribution = .equalSpacing stackView.spacing = 8 stackView.addArrangedSubview(titleLabel) stackView.addArrangedSubview(valuesLabel) contentView.addSubview(stackView) stackView.topAnchor.constraint(equalTo: contentView.layoutMarginsGuide.topAnchor).isActive = true stackView.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor).isActive = true stackView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor).isActive = true stackView.bottomAnchor.constraint(equalTo: contentView.layoutMarginsGuide.bottomAnchor).isActive = true } private func updateUI() { titleLabel.textColor = isDisabled ? .lightGray : Self.TextColor valuesLabel.textColor = isDisabled ? .lightGray : Self.ValueColor } }