PinterestUISwift 0.2.0

PinterestUISwift 0.2.0

Faris Albalawi 维护。



  • Faris Albalawi

PinterestUISwift

Language: Swift 5 CI Status Version License: MIT Platform

SkinnyExemplaryAcornweevil-small

功能

  • 支持头部和底部
  • 高度可定制
  • 更改列数
  • swift 5

示例

要运行示例项目,先克隆仓库,然后从 Example 目录运行 pod install

要求

安装

PinterestUISwift 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod 'PinterestUISwift'

使用方法

import PinterestUISwift

class ViewController: UIViewController, collectionViewFlowDataSource{
    
    // MARK: Variables
    var collectionView: UICollectionView!
    
   override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let layout = collectionViewLayout(delegate: self)
        if #available(iOS 10.0, *) {
            layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
        } else {
            // Fallback on earlier versions
        }
        collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height:self.view.frame.height), collectionViewLayout: layout)
        
        collectionView.backgroundColor = .white
        collectionView.dataSource = self
        collectionView.delegate = self
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.showsVerticalScrollIndicator = false
        view.addSubview(collectionView)
        
        collectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CollectionViewCell")
        
        let nib:UINib = UINib(nibName: "Header", bundle: nil)
        collectionView.register(nib, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "Header")
        
        
        
    }
}

功能

索引路径中元素的尺寸

   func sizeOfItemAtIndexPath(at indexPath: IndexPath) -> CGFloat {
       // take image height and return the height
        let height = Float.random(in: 80 ..< 400)
        return CGFloat(height)
    }

列数

   func numberOfCols(at section: Int) -> Int {
        return 2
        
    }

列间距

   func spaceOfCells(at section: Int) -> CGFloat{
        return 12
    }

UICollectionView Section 内边距

    func sectionInsets(at section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 10, left: 10, bottom: 50, right: 10)
    }

表头尺寸

   func sizeOfHeader(at section: Int) -> CGSize{
        return CGSize(width: view.frame.width, height: 150)
    }

附加内容高度

 func heightOfAdditionalContent(at indexPath : IndexPath) -> CGFloat{
        return 0
    }

作者

Faris Albalawi, [email protected]

许可

PinterestUISwift 在MIT许可下可用。更多信息请参阅LICENSE文件。