MyCollectionViewCell.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // MyCollectionViewCell.swift
  3. // SheeeeeeeeetExample
  4. //
  5. // Created by Jonas Ullström (ullstrm) on 2018-02-23.
  6. // Copyright © 2018 Jonas Ullström. All rights reserved.
  7. //
  8. import UIKit
  9. import Sheeeeeeeeet
  10. class MyCollectionViewCell: UICollectionViewCell {
  11. // MARK: - Overrides
  12. override func layoutSubviews() {
  13. super.layoutSubviews()
  14. badge?.layer.cornerRadius = 20
  15. }
  16. // MARK: - Item
  17. class Item: Equatable {
  18. init(title: String, subtitle: String) {
  19. self.title = title
  20. self.subtitle = subtitle
  21. self.isSelected = false
  22. }
  23. init(copy: Item) {
  24. self.title = copy.title
  25. self.subtitle = copy.subtitle
  26. self.isSelected = copy.isSelected
  27. }
  28. var title: String
  29. var subtitle: String
  30. var isSelected: Bool
  31. static func == (lhs: Item, rhs: Item) -> Bool {
  32. return lhs.title == rhs.title && lhs.subtitle == rhs.subtitle
  33. }
  34. }
  35. // MARK: - Outlets
  36. @IBOutlet weak var badge: UIView?
  37. @IBOutlet weak var titleLabel: UILabel?
  38. // MARK: - Public Functions
  39. func configureWith(item: Item) {
  40. let green = UIColor(hex: 0x4EA32A, alpha: 1)
  41. titleLabel?.text = item.title
  42. titleLabel?.textColor = item.isSelected ? .white : .black
  43. badge?.backgroundColor = item.isSelected ? green : .lightGray
  44. }
  45. }
  46. // MARK: - ActionSheetCollectionItemContentCell
  47. extension MyCollectionViewCell: ActionSheetCollectionItemContentCell {
  48. static let nib: UINib = UINib(nibName: "MyCollectionViewCell", bundle: nil)
  49. static let defaultSize = CGSize(width: 100, height: 100)
  50. static let leftInset: CGFloat = 10
  51. static let rightInset: CGFloat = 20
  52. static let topInset: CGFloat = 10
  53. static let bottomInset: CGFloat = 10
  54. static let itemSpacing: CGFloat = 0
  55. }