VLCSectionTableHeaderView.swift 2.3 KB

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