|
| 1 | +// |
| 2 | +// SettingHeaderView.swift |
| 3 | +// Presentation |
| 4 | +// |
| 5 | +// Created by 이동현 on 7/27/25. |
| 6 | +// |
| 7 | + |
| 8 | +import SnapKit |
| 9 | +import UIKit |
| 10 | + |
| 11 | +final class SettingHeaderView: UITableViewHeaderFooterView { |
| 12 | + private enum Layout { |
| 13 | + static let divideLineHeight: CGFloat = 6 |
| 14 | + static let titleLabelTopSpacing: CGFloat = 18 |
| 15 | + static let titleLabelHeight: CGFloat = 24 |
| 16 | + static let titleLabelLeadingSpacing: CGFloat = 20 |
| 17 | + } |
| 18 | + |
| 19 | + private let divideLine = UILabel() |
| 20 | + private let titleLabel = UILabel() |
| 21 | + private var titleLabelTopConstraint: Constraint? |
| 22 | + |
| 23 | + override init(reuseIdentifier: String?) { |
| 24 | + super.init(reuseIdentifier: reuseIdentifier) |
| 25 | + configureAttribute() |
| 26 | + configureLayout() |
| 27 | + } |
| 28 | + |
| 29 | + required init?(coder: NSCoder) { |
| 30 | + fatalError("init(coder:) has not been implemented") |
| 31 | + } |
| 32 | + |
| 33 | + private func configureAttribute() { |
| 34 | + divideLine.backgroundColor = BitnagilColor.gray99 |
| 35 | + |
| 36 | + titleLabel.font = BitnagilFont.init(style: .caption1, weight: .semiBold).font |
| 37 | + titleLabel.textColor = BitnagilColor.gray60 |
| 38 | + } |
| 39 | + |
| 40 | + private func configureLayout() { |
| 41 | + addSubview(divideLine) |
| 42 | + addSubview(titleLabel) |
| 43 | + |
| 44 | + divideLine.snp.makeConstraints { make in |
| 45 | + make.top.horizontalEdges.equalToSuperview() |
| 46 | + make.height.equalTo(Layout.divideLineHeight) |
| 47 | + } |
| 48 | + |
| 49 | + titleLabel.snp.makeConstraints { make in |
| 50 | + make.leading.equalToSuperview().offset(Layout.titleLabelLeadingSpacing) |
| 51 | + make.height.equalTo(Layout.titleLabelHeight) |
| 52 | + titleLabelTopConstraint = make.top.equalToSuperview() |
| 53 | + .offset(Layout.titleLabelTopSpacing) |
| 54 | + .constraint |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + func configure(shouldShowDivider: Bool, title: String) { |
| 59 | + let titleLabelTopSpacing: CGFloat = shouldShowDivider |
| 60 | + ? Layout.titleLabelTopSpacing |
| 61 | + : .zero |
| 62 | + |
| 63 | + divideLine.isHidden = !shouldShowDivider |
| 64 | + titleLabel.text = title |
| 65 | + titleLabelTopConstraint?.update(offset: titleLabelTopSpacing) |
| 66 | + } |
| 67 | +} |
0 commit comments