Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Scene/Settings/View/SettingsSectionHeader.swift

66 lines
2.0 KiB
Swift
Raw Normal View History

2021-04-08 13:47:31 +02:00
//
// SettingsSectionHeader.swift
// Mastodon
//
// Created by ihugo on 2021/4/8.
//
import UIKit
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
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)
backgroundColor = .clear
2021-04-08 13:47:31 +02:00
stackView.addArrangedSubview(titleLabel)
if let view = customView {
stackView.addArrangedSubview(view)
}
addSubview(stackView)
NSLayoutConstraint.activate([
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()
}
}