forked from videolan/vlc-ios
/
VLCSectionTableHeaderView.swift
65 lines (54 loc) · 2.32 KB
/
VLCSectionTableHeaderView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*****************************************************************************
* VLCSectionTableHeaderView.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2018 VideoLAN. All rights reserved.
* $Id$
*
* Author: Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
import Foundation
class VLCSectionTableHeaderView: UITableViewHeaderFooterView {
let separator = UIView()
@objc let label: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.font = PresentationTheme.current.font.tableHeaderFont
return label
}()
let stackView: UIStackView = {
let stackView = UIStackView()
stackView.spacing = 8
stackView.axis = .vertical
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}()
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
setupUI()
updateTheme()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupUI() {
stackView.addArrangedSubview(separator)
stackView.addArrangedSubview(label)
contentView.addSubview(stackView)
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15),
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15),
stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 15),
stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -9),
separator.heightAnchor.constraint(equalToConstant: 1)
])
}
@objc func updateTheme() {
contentView.backgroundColor = PresentationTheme.current.colors.background
separator.backgroundColor = PresentationTheme.current.colors.separatorColor
label.textColor = PresentationTheme.current.colors.cellTextColor
}
}