zoukankan      html  css  js  c++  java
  • swift UICollectionView使用

    方法1:创建 的时候注册 layout

        /// 时间view
        private lazy var timeCollectionV: UICollectionView = {
            1.直接注册 并设置好 UICollectionViewFlowLayout
            let layout = UICollectionViewFlowLayout()
    
            layout.itemSize = CGSize.init( (JY_DEVICE_WIDTH - 60) / 5, height: (JY_DEVICE_WIDTH - 60) / 5)
            layout.minimumLineSpacing = 10
            layout.minimumInteritemSpacing = 0
            layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
            
            let collectionV = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
            collectionV.register(UINib.init(nibName: "JYChooseShopTimeCollectionCell", bundle: nil), forCellWithReuseIdentifier: "JYChooseShopTimeCollectionCell")
            collectionV.delegate = self
            collectionV.dataSource = self
            collectionV.backgroundColor = UIColor.white
            return collectionV
        }()
    

      2.在代理里面设置UICollectionViewFlowLayout

    extension JYBespeakStylistAndTimeVc: UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{

    //最小行间距
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
            return 10;
        }
    
        //每个分区的内边距
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
            return UIEdgeInsetsMake(0, 0, 0, 0);
        }
    
        //item 的尺寸
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    
            let sizeItem : CGFloat = CGFloat(JY_DEVICE_WIDTH - 60) / 5
            return CGSize.init( sizeItem, height: sizeItem)
        }

    }



      

    3.其他设置

    // 一个分区几行
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return 60
        }
        
        //每个cell
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "JYChooseShopTimeCollectionCell", for: indexPath) as! JYChooseShopTimeCollectionCell
            
    //        cell.configModel(model: self.secmentControlTuple.timeArr![indexPath.row])
            return cell
        }

         func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

            

            DDLOG(message: "点击 item")

        }



      

  • 相关阅读:
    mongodb时间戳转换成格式化时间戳
    Python批量删除指定目录下的指定类型的文件
    Java将list数据导出到Excel——(八)
    Java读取Excel文件转换成JSON并转成List——(七)
    Java获取资源路径——(八)
    Java的IO流——(七)
    Java用System读取系统相关信息、环境变量——(六)
    POI导出带格式的Excel模板——(六)
    POI读取Excel(xls、xlsx均可以)——(四)
    POI导出Excel(xls、xlsx均可以,也支持图片)——(三)
  • 原文地址:https://www.cnblogs.com/qingzZ/p/9706577.html
Copyright © 2011-2022 走看看