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")

        }



      

  • 相关阅读:
    PHP设计模式:简单工厂
    MySQL实现两张表数据的同步
    SSH中Action的单例与多例
    Java日期时间操作的一些方法
    Null value was assigned to a property of primitive type setter of
    Android Studio创建AVD
    一台主机上安装多个Tomcat
    Tomcat指定的服务已存在
    Unsupported major.minor version 52.0问题的解决
    修改MySQL自动递增值
  • 原文地址:https://www.cnblogs.com/qingzZ/p/9706577.html
Copyright © 2011-2022 走看看