2021-04-08 13:47:31 +02:00
|
|
|
//
|
|
|
|
// SettingsSectionHeader.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by ihugo on 2021/4/8.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2021-04-13 11:53:18 +02:00
|
|
|
struct GroupedTableViewConstraints {
|
|
|
|
static let topMargin: CGFloat = 40
|
|
|
|
static let bottomMargin: CGFloat = 10
|
|
|
|
}
|
|
|
|
|
2021-04-08 13:47:31 +02:00
|
|
|
/// section header which supports add a custom view blelow the title
|
|
|
|
class SettingsSectionHeader: UIView {
|
|
|
|
lazy var titleLabel: UILabel = {
|
|
|
|
let label = UILabel()
|
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
label.font = .systemFont(ofSize: 13, weight: .regular)
|
|
|
|
label.textColor = Asset.Colors.Label.secondary.color
|
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
|
|
|
lazy var stackView: UIStackView = {
|
|
|
|
let view = UIStackView()
|
|
|
|
view.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.isLayoutMarginsRelativeArrangement = true
|
2021-04-13 11:53:18 +02:00
|
|
|
view.layoutMargins = UIEdgeInsets(
|
|
|
|
top: GroupedTableViewConstraints.topMargin,
|
|
|
|
left: 0,
|
|
|
|
bottom: GroupedTableViewConstraints.bottomMargin,
|
|
|
|
right: 0
|
|
|
|
)
|
2021-04-08 13:47:31 +02:00
|
|
|
view.axis = .vertical
|
|
|
|
return view
|
|
|
|
}()
|
|
|
|
|
|
|
|
init(frame: CGRect, customView: UIView? = nil) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
|
2021-06-08 11:26:12 +02:00
|
|
|
backgroundColor = .clear
|
|
|
|
|
2021-04-08 13:47:31 +02:00
|
|
|
stackView.addArrangedSubview(titleLabel)
|
|
|
|
if let view = customView {
|
|
|
|
stackView.addArrangedSubview(view)
|
|
|
|
}
|
|
|
|
|
|
|
|
addSubview(stackView)
|
|
|
|
NSLayoutConstraint.activate([
|
2021-04-13 11:53:18 +02:00
|
|
|
stackView.leadingAnchor.constraint(equalTo: self.readableContentGuide.leadingAnchor),
|
|
|
|
stackView.trailingAnchor.constraint(lessThanOrEqualTo: self.readableContentGuide.trailingAnchor),
|
2021-04-08 13:47:31 +02:00
|
|
|
stackView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
|
|
|
|
stackView.topAnchor.constraint(equalTo: self.topAnchor),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func update(title: String?) {
|
|
|
|
titleLabel.text = title?.uppercased()
|
|
|
|
}
|
|
|
|
}
|