1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // YMTodayGroupCollectionCell.swift
- // MvpGoods
- //
- // Created by 小花 on 2019/4/10.
- // Copyright © 2019 MVP. All rights reserved.
- //
- import UIKit
- class YMTodayGroupCollectionCell: UICollectionViewCell {
-
- typealias ClickClosure = (_ model: YMMainGoodModel) -> Void
- var clickClosure: ClickClosure?
-
- let GoodIdentifier: String = "GoodIdentifier"
-
- var collection: UICollectionView?
- var dataArr: [YMMainGoodModel]?
- var bgImgView: UIImageView!
-
- convenience required init?(coder aDecoder: NSCoder) {
- self.init()
- }
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- self.backgroundColor = UIColor.clear
- configSubViews()
- }
-
- func configSubViews() {
-
- bgImgView = UIImageView(frame: self.bounds)
- bgImgView.contentMode = .scaleAspectFill
- self.bgImgView.backgroundColor = UIColor.white
- self.addSubview(self.bgImgView)
-
-
- let layout = UICollectionViewFlowLayout()
- layout.scrollDirection = .horizontal
- let collectionView = UICollectionView(frame: CGRect(x: 0, y: fitSize(x: 40), width: self.width, height: fitSize(x: 165)), collectionViewLayout:layout)
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.backgroundColor = UIColor.clear
- collectionView.register(YMGroupChildCollectionCell.self, forCellWithReuseIdentifier: GoodIdentifier)
- self.addSubview(collectionView)
- self.collection = collectionView
- }
-
- var model: YMTodayGoodModel? {
- didSet {
- dataArr = model?.goodsList
- self.collection?.reloadData()
- bgImgView.setFadeImage(with: model?.adv_background_img)
- }
- }
-
-
- }
- extension YMTodayGroupCollectionCell: UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.dataArr?.count ?? 0
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GoodIdentifier, for: indexPath) as! YMGroupChildCollectionCell
- cell.model = dataArr?[indexPath.row]
- return cell
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- return UIEdgeInsetsMake(0, 10, 0, 10)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width: fitSize(x: 115), height: fitSize(x: 160))
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
- return fitSize(x: 14)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
- return 0
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- let model = self.dataArr?[indexPath.row]
- self.clickClosure?(model!)
- }
- }
|