优惠券swift版马甲包

YMTodayGroupCollectionCell.swift 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // YMTodayGroupCollectionCell.swift
  3. // MvpGoods
  4. //
  5. // Created by 小花 on 2019/4/10.
  6. // Copyright © 2019 MVP. All rights reserved.
  7. //
  8. import UIKit
  9. class YMTodayGroupCollectionCell: UICollectionViewCell {
  10. typealias ClickClosure = (_ model: YMMainGoodModel) -> Void
  11. var clickClosure: ClickClosure?
  12. let GoodIdentifier: String = "GoodIdentifier"
  13. var collection: UICollectionView?
  14. var dataArr: [YMMainGoodModel]?
  15. var bgImgView: UIImageView!
  16. convenience required init?(coder aDecoder: NSCoder) {
  17. self.init()
  18. }
  19. override init(frame: CGRect) {
  20. super.init(frame: frame)
  21. self.backgroundColor = UIColor.clear
  22. configSubViews()
  23. }
  24. func configSubViews() {
  25. bgImgView = UIImageView(frame: self.bounds)
  26. bgImgView.contentMode = .scaleAspectFill
  27. self.bgImgView.backgroundColor = UIColor.white
  28. self.addSubview(self.bgImgView)
  29. let layout = UICollectionViewFlowLayout()
  30. layout.scrollDirection = .horizontal
  31. let collectionView = UICollectionView(frame: CGRect(x: 0, y: fitSize(x: 40), width: self.width, height: fitSize(x: 165)), collectionViewLayout:layout)
  32. collectionView.delegate = self
  33. collectionView.dataSource = self
  34. collectionView.showsHorizontalScrollIndicator = false
  35. collectionView.backgroundColor = UIColor.clear
  36. collectionView.register(YMGroupChildCollectionCell.self, forCellWithReuseIdentifier: GoodIdentifier)
  37. self.addSubview(collectionView)
  38. self.collection = collectionView
  39. }
  40. var model: YMTodayGoodModel? {
  41. didSet {
  42. dataArr = model?.goodsList
  43. self.collection?.reloadData()
  44. bgImgView.setFadeImage(with: model?.adv_background_img)
  45. }
  46. }
  47. }
  48. extension YMTodayGroupCollectionCell: UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
  49. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  50. return self.dataArr?.count ?? 0
  51. }
  52. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  53. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GoodIdentifier, for: indexPath) as! YMGroupChildCollectionCell
  54. cell.model = dataArr?[indexPath.row]
  55. return cell
  56. }
  57. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  58. return UIEdgeInsetsMake(0, 10, 0, 10)
  59. }
  60. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  61. return CGSize(width: fitSize(x: 115), height: fitSize(x: 160))
  62. }
  63. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  64. return fitSize(x: 14)
  65. }
  66. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  67. return 0
  68. }
  69. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  70. let model = self.dataArr?[indexPath.row]
  71. self.clickClosure?(model!)
  72. }
  73. }