CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

PhotoCollectionView 1.5.2

PhotoCollectionView 1.5.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Luan Tran.



  • By
  • noblakit

PhotoCollectionView

Codacy Badge

Custom CollectionView like as Facebook Feed for iOS

Overview

Requirements

  • iOS 8.0+
  • Xcode 8+
  • Swift 3

Installation

CocoaPods

To integrate PhotoCollectionView into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'PhotoCollectionView', '~> 1.4.2' 

Then, run the following command:

$ pod install

Manually

  • Drag and drop Sources folder into your project

Usage

Create PhotoCollectionView

Use can create instance of PhotoCollectionView by code:

import PhotoCollectionView
let photoCollectionView = PhotoCollectionView(frame: CGRect(x: 0, y: 0, width: 320, height: 240))

or create an UIView in storyboard and Outlet it

import PhotoCollectionView
@IBOutlet weak var imageCollectionView: PhotoCollectionView!

PhotoCollectionViewDataSource

  • Extension PhotoCollectionViewDataSource for binding data
extension ViewController: PhotoCollectionViewDataSource {
    func numPhotos(in photoCollectionView: PhotoCollectionView) -> Int {
        // Return count photo.
        return 10
    }
    
    // You can use image for data
    func photoColletionView(_ photoCollectionView: PhotoCollectionView, imageAt index: Int) -> UIImage? {
    	// return image need to show.
        return UIImage(named: "image\(index + 1)")
    }

    // or use image url
    func photoCollectionView(_ photoCollectionView: PhotoCollectionView, urlImageAt index: Int) -> URL? {
        return URL(string: *your image URL here*)
    }

}
  • Set dataSource of PhotoCollectionView
imageCollectionView.dataSource = self

PhotoCollectionViewDelegate

Handle image selection in PhotoCollectionView

imageCollectionView.delegate = self
extension ViewController: PhotoCollectionViewDelegate {
    func photoCollectionView(_ photoCollectionView: PhotoCollectionView, didSelectImageAt index: Int) {
        print("Press at index \(index)")
    }
}

TODO

Author

Luan Tran - [email protected]

License

MIT