RedemptionAreaSpecialTwoTableViewCell.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // RedemptionAreaSpecialTwoTableViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/7/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class RedemptionAreaSpecialTwoTableViewCell: UITableViewCell {
  10. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RedemptionAreaSpecialTwoTableViewCell {
  11. let ID = "RedemptionAreaSpecialTwoTableViewCell"
  12. tableView.register(RedemptionAreaSpecialTwoTableViewCell.self, forCellReuseIdentifier: ID)
  13. let cell : RedemptionAreaSpecialTwoTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! RedemptionAreaSpecialTwoTableViewCell
  14. cell.indexPath = indexPath
  15. return cell
  16. }
  17. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  18. super.init(style: style, reuseIdentifier: reuseIdentifier)
  19. setupViews()
  20. setupLayouts()
  21. }
  22. required init?(coder aDecoder: NSCoder) {
  23. fatalError("init(coder:) has not been implemented")
  24. }
  25. var indexPath: IndexPath? {
  26. didSet {
  27. }
  28. }
  29. //MRAK: - 设置View
  30. private func setupViews() {
  31. self.selectionStyle = .none
  32. backgroundColor = UIColor.white
  33. addSubview(collectionView)
  34. }
  35. private func setupLayouts() {
  36. collectionView.snp.remakeConstraints {(make) in
  37. make.top.left.right.equalToSuperview()
  38. make.height.equalTo(275*kScaleWidth)
  39. }
  40. }
  41. private lazy var collectionView: UICollectionView = {
  42. let collectionView = UICollectionView.init(frame: CGRect.zero,collectionViewLayout: collectionViewLayout)
  43. collectionView.backgroundColor = UIColor.white
  44. collectionView.delegate = self;
  45. collectionView.dataSource = self;
  46. collectionView.showsVerticalScrollIndicator = false
  47. collectionView.showsHorizontalScrollIndicator = false
  48. collectionView.isScrollEnabled = false
  49. return collectionView
  50. }()
  51. private lazy var collectionViewLayout: SepcialTwoTypeLayout = {
  52. let collectionViewLayout = SepcialTwoTypeLayout()
  53. return collectionViewLayout
  54. }()
  55. var cmsRedemptionAreaContent: CMSRedemptionAreaContent? {
  56. didSet{
  57. collectionView.reloadData()
  58. }
  59. }
  60. }
  61. extension RedemptionAreaSpecialTwoTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
  62. func numberOfSections(in collectionView: UICollectionView) -> Int {
  63. if !(cmsRedemptionAreaContent?.rule?.isEmpty ?? true) {
  64. return 1
  65. }else {
  66. return 0
  67. }
  68. }
  69. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  70. if !(cmsRedemptionAreaContent?.rule?.isEmpty ?? true) {
  71. return cmsRedemptionAreaContent?.rule?.count ?? 0
  72. }else {
  73. return 0
  74. }
  75. }
  76. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  77. let cmsRedemptionAreaRule = cmsRedemptionAreaContent?.rule?[indexPath.row]
  78. let cell = SpecialTwoTypeCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
  79. cell.cmsRedemptionAreaRule = cmsRedemptionAreaRule
  80. return cell
  81. }
  82. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  83. let cmsRedemptionAreaRule = cmsRedemptionAreaContent?.rule?[indexPath.row]
  84. RedemptionAreaViewModel.shared.pushVC(cmsRedemptionAreaRule: cmsRedemptionAreaRule)
  85. }
  86. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  87. return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  88. }
  89. }