CustomOverrideCollectionViewCell.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // CustomOverrideCollectionViewCell.swift
  3. // LoopKitUI
  4. //
  5. // Created by Michael Pangburn on 11/5/19.
  6. // Copyright © 2019 LoopKit Authors. All rights reserved.
  7. //
  8. import UIKit
  9. final class CustomOverrideCollectionViewCell: UICollectionViewCell, IdentifiableClass {
  10. @IBOutlet weak var titleLabel: UILabel!
  11. private lazy var overlayDimmerView: UIView = {
  12. let view = UIView()
  13. view.backgroundColor = .systemBackground
  14. view.alpha = 0
  15. view.translatesAutoresizingMaskIntoConstraints = false
  16. return view
  17. }()
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. let selectedBackgroundView = UIView()
  21. self.selectedBackgroundView = selectedBackgroundView
  22. selectedBackgroundView.backgroundColor = .tertiarySystemFill
  23. backgroundColor = .secondarySystemGroupedBackground
  24. layer.cornerCurve = .continuous
  25. layer.cornerRadius = 16
  26. addSubview(overlayDimmerView)
  27. NSLayoutConstraint.activate([
  28. overlayDimmerView.leadingAnchor.constraint(equalTo: leadingAnchor),
  29. overlayDimmerView.trailingAnchor.constraint(equalTo: trailingAnchor),
  30. overlayDimmerView.topAnchor.constraint(equalTo: topAnchor),
  31. overlayDimmerView.bottomAnchor.constraint(equalTo: bottomAnchor)
  32. ])
  33. }
  34. override func prepareForReuse() {
  35. removeOverlay(animated: false)
  36. }
  37. func applyOverlayToFade(animated: Bool) {
  38. if animated {
  39. UIView.animate(withDuration: 0.3, animations: {
  40. self.overlayDimmerView.alpha = 0.5
  41. })
  42. } else {
  43. self.overlayDimmerView.alpha = 0.5
  44. }
  45. }
  46. func removeOverlay(animated: Bool) {
  47. if animated {
  48. UIView.animate(withDuration: 0.3, animations: {
  49. self.overlayDimmerView.alpha = 0
  50. })
  51. } else {
  52. self.overlayDimmerView.alpha = 0
  53. }
  54. }
  55. }