1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- //
- // YMOtherHeaderView.swift
- // MvpGoods
- //
- // Created by 小花 on 2019/4/11.
- // Copyright © 2019 MVP. All rights reserved.
- //
- import UIKit
- class YMOtherHeaderView: UIView {
- typealias ClickClosure = (_ model: YMOtherHeaderModel) -> Void
- var clickClosure: ClickClosure?
-
- var KMainGoodCell = "MainGoodCell"
- var KHeaderKey = "KHeaderKey"
- var collectionView: UICollectionView?
-
- var dataArr: [YMOtherHeaderModel]?
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- self.initSubViews()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func initSubViews() {
- let layout = UICollectionViewFlowLayout()
- layout.scrollDirection = .horizontal
- layout.itemSize = CGSize(width: 70, height: 80)
- let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: SCREENW, height: self.height), collectionViewLayout:layout)
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.backgroundColor = UIColor.gloadGrayColor()
- collectionView.register(YMOtherHeaderCell.self, forCellWithReuseIdentifier: KMainGoodCell)
- collectionView.backgroundColor = UIColor.white
- self.addSubview(collectionView)
- self.collectionView = collectionView
- }
-
- func setDataArr(data: [YMOtherHeaderModel]){
- dataArr = data
- self.collectionView?.reloadData()
- }
- }
- extension YMOtherHeaderView: 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: KMainGoodCell, for:indexPath) as! YMOtherHeaderCell
- cell.model = self.dataArr![indexPath.row]
- return cell
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- let model = self.dataArr?[indexPath.row]
- self.clickClosure?(model!)
- }
-
- }
|