IOS橫線滾動(dòng)視圖的實(shí)現(xiàn)---方式二

//初始化
 public var mDataList = [ReuniteMarketModel]()
    // MARK: - 懶加載九宮格分類按鈕
    private lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout.init()
        layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        layout.itemSize = CGSize(width:(YYScreenWidth-20)/3, height:100)
        layout.scrollDirection = .horizontal
        let collectionView = UICollectionView.init(frame:.zero, collectionViewLayout: layout)
        collectionView.contentSize = CGSize.init(width: YYScreenWidth-20, height: 100)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = UIColor.white
        collectionView.showsVerticalScrollIndicator = false
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.register(HomeSelfSelectCell.self, forCellWithReuseIdentifier:"SelfCellIdentifier")
        
        return collectionView
    }()

self.addSubview(self.collectionView)
        self.collectionView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(title1.snp.bottom).offset(10)
            make.height.equalTo(100)
        }


//實(shí)現(xiàn)代理

extension HomeHeadViewNew: UICollectionViewDataSource, UICollectionViewDelegate {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.mDataList.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:HomeSelfSelectCell = collectionView.dequeueReusableCell(withReuseIdentifier: "SelfCellIdentifier", for: indexPath) as! HomeSelfSelectCell
        cell.backgroundColor = UIColor.white
        cell.mAllMarketModel = self.mDataList[indexPath.row]
        return cell
    }
}


//加載數(shù)據(jù)
self.collectionView.reloadData()


//cell

class HomeSelfSelectCell: UICollectionViewCell{
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
   
    
    func setUpUI(){

      
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    var mAllMarketModel: ReuniteMarketModel? {
        didSet {

        }
    }

}



?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容