MyCollectionViewCell.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /*
  9. This cell is used by the example app, to populate the cells
  10. of the `CollectionActionSheet` example action sheet.
  11. */
  12. import UIKit
  13. import Sheeeeeeeeet
  14. class MyCollectionViewCell: UICollectionViewCell {
  15. // MARK: - Overrides
  16. override func layoutSubviews() {
  17. super.layoutSubviews()
  18. badge?.layer.cornerRadius = 20
  19. }
  20. // MARK: - Item
  21. class Item: Equatable {
  22. init(title: String, subtitle: String) {
  23. self.title = title
  24. self.subtitle = subtitle
  25. self.isSelected = false
  26. }
  27. init(copy: Item) {
  28. self.title = copy.title
  29. self.subtitle = copy.subtitle
  30. self.isSelected = copy.isSelected
  31. }
  32. var title: String
  33. var subtitle: String
  34. var isSelected: Bool
  35. static func == (lhs: Item, rhs: Item) -> Bool {
  36. return lhs.title == rhs.title && lhs.subtitle == rhs.subtitle
  37. }
  38. }
  39. // MARK: - Outlets
  40. @IBOutlet weak var badge: UIView?
  41. @IBOutlet weak var titleLabel: UILabel?
  42. // MARK: - Public Functions
  43. func configureWith(item: Item) {
  44. let green = UIColor(hex: 0x4EA32A, alpha: 1)
  45. titleLabel?.text = item.title
  46. titleLabel?.textColor = item.isSelected ? .white : .black
  47. badge?.backgroundColor = item.isSelected ? green : .lightGray
  48. }
  49. }
  50. // MARK: - ActionSheetCollectionItemContentCell
  51. extension MyCollectionViewCell: ActionSheetCollectionItemContentCell {
  52. static let nib: UINib = UINib(nibName: "MyCollectionViewCell", bundle: nil)
  53. static let defaultSize = CGSize(width: 100, height: 100)
  54. static let leftInset: CGFloat = 10
  55. static let rightInset: CGFloat = 20
  56. static let topInset: CGFloat = 10
  57. static let bottomInset: CGFloat = 10
  58. static let itemSpacing: CGFloat = 0
  59. }