zoukankan      html  css  js  c++  java
  • swift 快速创建一些基本控件

    1.tableview 

        private lazy var cellId = "cellId"
        fileprivate lazy var tv : UITableView = {
            let tv = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
            tv.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
            tv.translatesAutoresizingMaskIntoConstraints = false
            tv.separatorStyle = .none
            tv.backgroundColor = UIColor.white
            tv.delegate = self
            tv.dataSource = self
            tv.bounces = false
            return tv
        }()
    
    
    
        // MARK: - UITableViewDelegate, UITableViewDataSource
        extension JYJYRtbMineVc:UITableViewDelegate, UITableViewDataSource{
            func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                return 1
            }
            
            func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
                
                return cell
            }
        }
    

      

    2.流水布局

        let JYLoadImageCollectionCellId = "JYLoadImageCollectionCell"
        let JYAddImageCollectionCellId = "JYAddImageCollectionCell"
        private lazy var collectionView: UICollectionView = {
            let layout = UICollectionViewFlowLayout()
            let itemWidth = CGFloat(Int((JY_DEVICE_WIDTH - 10 * 4)/3))
            let itemHeight = itemWidth
            layout.itemSize = CGSize( itemWidth, height: itemHeight)
            layout.minimumLineSpacing = 0
            layout.minimumInteritemSpacing = 0
            layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
            
            let collectionV = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
            collectionV.translatesAutoresizingMaskIntoConstraints = false
            //        collectionV.register(UINib.init(nibName: "JYChooseShopTimeCollectionCell", bundle: nil), forCellWithReuseIdentifier: "JYChooseShopTimeCollectionCell")
            collectionV.register(JYLoadImageCollectionCell.classForCoder(), forCellWithReuseIdentifier: JYLoadImageCollectionCellId)
            collectionV.register(JYAddImageCollectionCell.classForCoder(), forCellWithReuseIdentifier: JYAddImageCollectionCellId)
            collectionV.delegate = self
            collectionV.dataSource = self
            collectionV.backgroundColor = .white
            collectionV.showsHorizontalScrollIndicator = false
            collectionV.showsVerticalScrollIndicator = false
            
            return collectionV
        }()
    
    
    
        extension JYShopDetailFigureVc:UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
            func numberOfSections(in collectionView: UICollectionView) -> Int {
                return 1
            }
            
            func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                return 1
            }
            
            func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                
                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: JYAddImageCollectionCellId, for: indexPath) as! JYAddImageCollectionCell
                return cell
            }
            
            func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            }
        }
    

      

  • 相关阅读:
    【随笔】野生在左 科班在右——数据结构学习誓师贴
    javascript基础修炼(7)——Promise,异步,可靠性
    express中间件系统的基本实现
    javascript基础修炼(6)——前端路由的基本原理
    javascript基础修炼(5)—Event Loop(Node.js)
    一统江湖的大前端(7)React.js-从开发者到工程师
    一统江湖的大前端(6)commander.js + inquirer.js——懒,才是第一生产力
    一统江湖的大前端(5)editorconfig + eslint——你的代码里藏着你的优雅
    Jmeter接口测试之用户自定义变量(九)
    Jmeter4.0接口测试之案例实战(七)
  • 原文地址:https://www.cnblogs.com/qingzZ/p/10191752.html
Copyright © 2011-2022 走看看