ActionSheetCell.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. class ActionSheetCell: UICollectionViewCell {
  12. @objc static var identifier: String {
  13. return String(describing: self)
  14. }
  15. let icon: UIImageView = {
  16. let icon = UIImageView()
  17. icon.translatesAutoresizingMaskIntoConstraints = false
  18. icon.contentMode = .scaleAspectFit
  19. return icon
  20. }()
  21. let name: UILabel = {
  22. let name = UILabel()
  23. name.textColor = PresentationTheme.current.colors.cellTextColor
  24. name.font = UIFont.systemFont(ofSize: 15)
  25. name.translatesAutoresizingMaskIntoConstraints = false
  26. name.setContentHuggingPriority(.defaultLow, for: .horizontal)
  27. return name
  28. }()
  29. let stackView: UIStackView = {
  30. let stackView = UIStackView()
  31. stackView.spacing = 15.0
  32. stackView.axis = .horizontal
  33. stackView.alignment = .center
  34. stackView.translatesAutoresizingMaskIntoConstraints = false
  35. return stackView
  36. }()
  37. override init(frame: CGRect) {
  38. super.init(frame: frame)
  39. setupViews()
  40. }
  41. required init?(coder aDecoder: NSCoder) {
  42. super.init(coder: aDecoder)
  43. setupViews()
  44. }
  45. private func setupViews() {
  46. backgroundColor = PresentationTheme.current.colors.background
  47. stackView.addArrangedSubview(icon)
  48. stackView.addArrangedSubview(name)
  49. addSubview(stackView)
  50. var guide: LayoutAnchorContainer = self
  51. if #available(iOS 11.0, *) {
  52. guide = safeAreaLayoutGuide
  53. }
  54. NSLayoutConstraint.activate([
  55. icon.heightAnchor.constraint(equalToConstant: 25),
  56. icon.widthAnchor.constraint(equalTo: icon.heightAnchor),
  57. stackView.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
  58. stackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
  59. stackView.heightAnchor.constraint(equalTo: heightAnchor),
  60. stackView.topAnchor.constraint(equalTo: topAnchor)
  61. ])
  62. }
  63. }