2020-09-17 新项目第一天

2020-09-19  本文已影响0人  菲特峰

首页设计初稿如图,暂时没有切图自己先搭建一个框架,项目使用swift开发

image.png

界面分析

实现瀑布流布局

    //设置瀑布流
    func setupCollectionView() {
        let waterFallLayout =  LFWaterFallLayout.init()
        waterFallLayout.delegate = self
        let collectionView = UICollectionView.init(frame:CGRect.init(x: 0, y: 0, width: kScreenWidth, height: kScreenHeigth-tabBarHeight-navigationBarHeight-250), collectionViewLayout: waterFallLayout)
        
        collectionView.dataSource = self
        collectionView.backgroundColor = AppColor.white
        collectionView.register(nibWithCellClass: PXSWaterFallCell.self)
        
        self.tableView.tableFooterView = collectionView
        
    }

实现代理方法

extension HomeViewController {

        func numberOfSections(in collectionView: UICollectionView) -> Int {
            return 1
        }
        
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return 10
        }
        
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            let cell =  collectionView.dequeueReusableCell(withClass: PXSWaterFallCell.self, for: indexPath)
            return cell
        }
    
    
        func heightForItemAtIndexPath(indexPath: Int, itemWidth: CGFloat, waterFallLayout: LFWaterFallLayout) -> CGFloat {
            let y = arc4random() % UInt32(200) + UInt32(60)

            return CGFloat(y)

        }
        func rowMarginInWaterFallLayout(waterFallLayout: LFWaterFallLayout) -> CGFloat {
            return 20
        }
        
        func columnCountInWaterFallLayout(waterFallLayout: LFWaterFallLayout) -> Int {
            return 2
        }
        

}

image.png

到这首页差不多界面搭建完毕了

上一篇 下一篇

猜你喜欢

热点阅读