VLCActionSheetSectionHeader.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*****************************************************************************
  2. * VLCActionSheetSectionHeader.swift
  3. *
  4. * Copyright © 2018 VLC authors and VideoLAN
  5. * Copyright © 2018 Videolabs
  6. *
  7. * Authors: Soomin Lee <bubu@mikan.io>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. class VLCActionSheetSectionHeader: UIView {
  12. static let identifier = "VLCActionSheetSectionHeader"
  13. let title: UILabel = {
  14. let title = UILabel()
  15. title.font = UIFont.boldSystemFont(ofSize: 13)
  16. title.translatesAutoresizingMaskIntoConstraints = false
  17. return title
  18. }()
  19. let separator: UIView = {
  20. let separator = UIView()
  21. separator.backgroundColor = .lightGray
  22. separator.translatesAutoresizingMaskIntoConstraints = false
  23. return separator
  24. }()
  25. lazy var guide: LayoutAnchorContainer = {
  26. var guide: LayoutAnchorContainer = self
  27. if #available(iOS 11.0, *) {
  28. guide = safeAreaLayoutGuide
  29. }
  30. return guide
  31. }()
  32. override init(frame: CGRect) {
  33. super.init(frame: frame)
  34. setupTitle()
  35. setupSeparator()
  36. }
  37. required init?(coder aDecoder: NSCoder) {
  38. super.init(coder: aDecoder)
  39. setupTitle()
  40. setupSeparator()
  41. }
  42. fileprivate func setupSeparator() {
  43. addSubview(separator)
  44. NSLayoutConstraint.activate([
  45. separator.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
  46. separator.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
  47. separator.heightAnchor.constraint(equalToConstant: 0.5),
  48. separator.topAnchor.constraint(equalTo: bottomAnchor, constant: -1)
  49. ])
  50. }
  51. fileprivate func setupTitle() {
  52. addSubview(title)
  53. NSLayoutConstraint.activate([
  54. title.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
  55. title.centerYAnchor.constraint(equalTo: centerYAnchor),
  56. title.centerXAnchor.constraint(equalTo: centerXAnchor),
  57. title.topAnchor.constraint(equalTo: topAnchor)
  58. ])
  59. }
  60. }