// // EQNBaseContainerTableViewCell.swift // Earthquake Network // // Created by Andrea Busi on 14/06/24. // Copyright © 2024 Earthquake Network. All rights reserved. // import UIKit class EQNBaseContainerTableViewCell: UITableViewCell { static let DefaultVerticalSpacing: CGFloat = 10.0 static let DefaultPadding: CGFloat = 8.0 lazy var containerView: UIView = { let view = UIView(frame: .zero) view.translatesAutoresizingMaskIntoConstraints = false view.backgroundColor = .white view.layer.cornerRadius = AppTheme.shared.cardCornerRadius view.layer.masksToBounds = false // add shadow view.layer.shadowColor = UIColor.black.cgColor view.layer.shadowOpacity = 0.5 view.layer.shadowOffset = CGSize(width: 0, height: 2) view.layer.shadowRadius = 2 return view }() private lazy var headerLabel: UILabel = { let label = EQNEdgeInsetLabel() label.translatesAutoresizingMaskIntoConstraints = false label.backgroundColor = AppTheme.Colors.lightBlue label.font = .systemFont(ofSize: 17.0, weight: .medium) label.textColor = .white return label }() private lazy var emptyTopView: UIView = { let view = UIView(frame: .zero) view.backgroundColor = .clear return view }() var topView: UIView { isHeaderVisible ? headerLabel : emptyTopView } var isHeaderVisible: Bool { true } var headerText: String { "" } // MARK: - Init override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) setupUI() updateUI() } required init?(coder: NSCoder) { super.init(coder: coder) setupUI() updateUI() } // MARK: - Internal func setupUI() { selectionStyle = .default backgroundColor = .clear contentView.addSubview(containerView) containerView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 4.0).isActive = true containerView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -8.0).isActive = true containerView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 8.0).isActive = true containerView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -4.0).isActive = true if isHeaderVisible { containerView.addSubview(headerLabel) headerLabel.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true headerLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true headerLabel.heightAnchor.constraint(equalToConstant: 26.0).isActive = true } else { containerView.addSubview(emptyTopView) emptyTopView.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true emptyTopView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true emptyTopView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor).isActive = true emptyTopView.heightAnchor.constraint(equalToConstant: 0.0).isActive = true } } func updateUI() { // setup titles, colors and UI stuff here headerLabel.text = headerText } }