ActionSheetCell.swift 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*****************************************************************************
  2. * ActionSheetCell.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. @objc(VLCActionSheetCell)
  12. class ActionSheetCell: UICollectionViewCell {
  13. @objc static var identifier: String {
  14. return String(describing: self)
  15. }
  16. override var isSelected: Bool {
  17. didSet {
  18. let colors = PresentationTheme.current.colors
  19. name.textColor = isSelected ? colors.orangeUI : colors.cellTextColor
  20. tintColor = isSelected ? colors.orangeUI : colors.cellDetailTextColor
  21. checkmark.isHidden = !isSelected
  22. }
  23. }
  24. let icon: UIImageView = {
  25. let icon = UIImageView()
  26. icon.translatesAutoresizingMaskIntoConstraints = false
  27. icon.contentMode = .scaleAspectFit
  28. return icon
  29. }()
  30. let name: UILabel = {
  31. let name = UILabel()
  32. name.textColor = PresentationTheme.current.colors.cellTextColor
  33. name.font = UIFont.systemFont(ofSize: 15)
  34. name.translatesAutoresizingMaskIntoConstraints = false
  35. name.setContentHuggingPriority(.defaultLow, for: .horizontal)
  36. return name
  37. }()
  38. let checkmark: UILabel = {
  39. let checkmark = UILabel()
  40. checkmark.text = "✓"
  41. checkmark.font = UIFont.systemFont(ofSize: 18)
  42. checkmark.textColor = PresentationTheme.current.colors.orangeUI
  43. checkmark.translatesAutoresizingMaskIntoConstraints = false
  44. checkmark.isHidden = true
  45. return checkmark
  46. }()
  47. let stackView: UIStackView = {
  48. let stackView = UIStackView()
  49. stackView.spacing = 15.0
  50. stackView.axis = .horizontal
  51. stackView.alignment = .center
  52. stackView.translatesAutoresizingMaskIntoConstraints = false
  53. return stackView
  54. }()
  55. override init(frame: CGRect) {
  56. super.init(frame: frame)
  57. setupViews()
  58. }
  59. required init?(coder aDecoder: NSCoder) {
  60. super.init(coder: aDecoder)
  61. setupViews()
  62. }
  63. private func setupViews() {
  64. backgroundColor = PresentationTheme.current.colors.background
  65. stackView.addArrangedSubview(icon)
  66. stackView.addArrangedSubview(name)
  67. stackView.addArrangedSubview(checkmark)
  68. addSubview(stackView)
  69. var guide: LayoutAnchorContainer = self
  70. if #available(iOS 11.0, *) {
  71. guide = safeAreaLayoutGuide
  72. }
  73. NSLayoutConstraint.activate([
  74. icon.heightAnchor.constraint(equalToConstant: 25),
  75. icon.widthAnchor.constraint(equalTo: icon.heightAnchor),
  76. stackView.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
  77. stackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
  78. stackView.heightAnchor.constraint(equalTo: heightAnchor),
  79. stackView.topAnchor.constraint(equalTo: topAnchor)
  80. ])
  81. }
  82. }