niroshanf/ANFAdaptiveCollectionView


Easy Adaptive collection view that adjust to any screen size

License: MIT

Language: Swift


ANFAdaptiveCollectionView

CI Status Version License Platform

Example

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

Requirements

Installation

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

pod 'ANFAdaptiveCollectionView'

Example Setup

Storyboard / Xib

*) Change the collection view layout objects class

  • ANFAdaptiveLayout.swift - Left to Right Layout

  • ANFAdaptiveLayoutRightToLeft.swift - Right to Left Layout

*) Change the Estimated row height property of the layout class to the appropriate cell height

Code

View Controller

@IBOutlet var collectionView: UICollectionView!

override func viewDidLoad() {
        super.viewDidLoad()

        if let layout = self.collectionView.collectionViewLayout as? ANFAdaptiveLayoutRightToLeft {
            layout.delegate = self
        }

       collectionView.register(UINib(nibName: "ArticleCell", bundle: nil), forCellWithReuseIdentifier: "Cell")
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)
        
        DispatchQueue.main.async(execute: {
            self.collectionView.reloadData()
        })
}


// Delegate

extension ViewController: ANFAdaptiveLayoutDelegate {
    
    func numberOfColumnsForLandscapePhone(collectionView: UICollectionView) -> Int {
        2
    }
    
    func numberOfColumnsForPortraitPhone(collectionView: UICollectionView) -> Int {
        1
    }
    
    func numberOfColumnsForLandscapePad(collectionView: UICollectionView) -> Int {
        4
    }
    
    func numberOfColumnsForPortraitPad(collectionView: UICollectionView) -> Int {
        2
    }
}

Collectionview Cell

import ANFAdaptiveCollectionView

class ArticleCell: ANFAdaptiveCell {

}

Author

Anthony Niroshan Fernandez, niroshanf@gmail.com

License

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

Project Statistics

Sourcerank 3
Repository Size 41 KB
Stars 0
Forks 0
Watchers 1
Open issues 0
Dependencies 2
Contributors 1
Tags 1
Created
Last updated
Last pushed

Top Contributors See all

niroshanf

Packages Referencing this Repo

ANFAdaptiveCollectionView
Easy Adaptive collection view that adjust to any screen size
Latest release 0.1.0 - Published

Recent Tags See all

0.1.0 January 11, 2020

Something wrong with this page? Make a suggestion

Last synced: 2020-01-15 00:18:55 UTC

Login to resync this repository