PinterestUISwift 0.2.0

PinterestUISwift 0.2.0

Maintained by Faris Albalawi.



  • By
  • Faris Albalawi

PinterestUISwift

Language: Swift 5 CI Status Version License: MIT Platform

SkinnyExemplaryAcornweevil-small

Features

  • Supports Headers and Footers
  • Highly Customizable
  • Change the number of columns
  • swift 5

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

PinterestUISwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PinterestUISwift'

Usage

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

Functions

Height of the items at index path:

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

number of columns:

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

space of columns:

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

UICollectionview Section Inset:

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

size Of Header:

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

height Of Additional Content:

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

Author

Faris Albalawi, [email protected]

License

PinterestUISwift is available under the MIT license. See the LICENSE file for more info.