ActionSheetSectionHeader.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*****************************************************************************
  2. * ActionSheetSectionHeader.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 ActionSheetSectionHeader: UIView {
  12. static let identifier = "VLCActionSheetSectionHeader"
  13. var cellHeight: CGFloat {
  14. return 50
  15. }
  16. let title: UILabel = {
  17. let title = UILabel()
  18. title.font = UIFont.boldSystemFont(ofSize: 17)
  19. title.textColor = PresentationTheme.current.colors.cellTextColor
  20. title.translatesAutoresizingMaskIntoConstraints = false
  21. return title
  22. }()
  23. let separator: UIView = {
  24. let separator = UIView()
  25. separator.backgroundColor = .lightGray
  26. separator.translatesAutoresizingMaskIntoConstraints = false
  27. return separator
  28. }()
  29. lazy var guide: LayoutAnchorContainer = {
  30. var guide: LayoutAnchorContainer = self
  31. if #available(iOS 11.0, *) {
  32. guide = safeAreaLayoutGuide
  33. }
  34. return guide
  35. }()
  36. override init(frame: CGRect) {
  37. super.init(frame: frame)
  38. setupTitle()
  39. setupSeparator()
  40. }
  41. required init?(coder aDecoder: NSCoder) {
  42. super.init(coder: aDecoder)
  43. setupTitle()
  44. setupSeparator()
  45. }
  46. fileprivate func setupSeparator() {
  47. addSubview(separator)
  48. NSLayoutConstraint.activate([
  49. separator.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
  50. separator.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
  51. separator.heightAnchor.constraint(equalToConstant: 0.5),
  52. separator.topAnchor.constraint(equalTo: bottomAnchor, constant: -1)
  53. ])
  54. }
  55. fileprivate func setupTitle() {
  56. addSubview(title)
  57. NSLayoutConstraint.activate([
  58. title.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
  59. title.topAnchor.constraint(equalTo: topAnchor, constant: 20)
  60. ])
  61. }
  62. }