This Cocoa Pod gives you an image grid view which displays images. Images can be dragged and dropped to be reordered. There are buttons to delete images and add new images. The grid automatically resizes when more images are added. You can hook in delegate methods to control the behaviour when the user taps delete or add. This was originally designed for a profile picture selector on an edit profile screen.
To run the example project, clone the repo, and run pod install
from the Example directory first.
It's as simple as:
let imageGridView = ImageGridView(frame: imageGridViewContainer.bounds)
imageGridView.delegate = self
imageGridView.datasource = self
imageGridViewContainer.addSubview(imageGridView)
imageGridView.reload()
Just implement the datasource method:
func imageGridViewImages(_ imageGridView: ImageGridView) -> [UIImage]
And the delegate methods:
func imageGridView(_ imageGridView: ImageGridView, didTapDeleteForImage index: Int)
func imageGridViewDidTapAddImage(_ imageGridView: ImageGridView)
func imageGridView(_ imageGridView: ImageGridView, didMoveImage fromIndex: Int, toIndex: Int)
You can also set additional options to override the defaults:
imageGridView.maxCapacity = 7
For a full working example, see ViewController.swift
in the Example project.
ImageGridView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ImageGridView'
miraan, [email protected]
ImageGridView is available under the MIT license. See the LICENSE file for more info.