VLCActionSheetCell.swift 2.4 KB

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