Latest 1.0.4
Homepage https://github.com/ahmetkgunay/CollageView
License MIT
Platforms ios 8.0, requires ARC
Authors

Version
License
Platform

Language


Twitter: @ahmtgny


CollageView

Custom View, collageView implementation with pure swift4.

This Library’s aim is to make easily photo collage views.

Anim

Usage

Like any other customViews, can be used with changing your view’s class name as "CollageView" or initialize in code.

  • Interface Builder

CollageView


class ViewController: UIViewController {

    //Assume that you have images array, or you can fetch from remote
    let images = [#imageLiteral(resourceName: "amsterdam"), #imageLiteral(resourceName: "istanbul"), #imageLiteral(resourceName: "camera"), #imageLiteral(resourceName: "istanbul2"), #imageLiteral(resourceName: "mirror")];

    @IBOutlet weak var collageView: CollageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Set delegate to trigger click events on imageview's
        collageView.delegate    = self
        // Set datasource to fill your collageView with data
        collageView.dataSource  = self
    }

    deinit {
        collageView.delegate    = nil
        collageView.dataSource  = nil
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
  • Initialize in Code

class ViewController: UIViewController {

    //Assume that you have images array, or you can fetch from remote
    let images = [#imageLiteral(resourceName: "amsterdam"), #imageLiteral(resourceName: "istanbul"), #imageLiteral(resourceName: "camera"), #imageLiteral(resourceName: "istanbul2"), #imageLiteral(resourceName: "mirror")];

    var collageView = CollageView(frame: .zero)

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(collageView)

        // Set delegate to trigger click events on imageview's
        collageView.delegate    = self
        // Set datasource to fill your collageView with data
        collageView.dataSource  = self
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        // Example frame
        collageView.frame = view.bounds
    }

    deinit {
        collageView.delegate    = nil
        collageView.dataSource  = nil
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

After that, fill required dataSource and optional delegate methods


extension ViewController: CollageViewDataSource {

    func collageViewNumberOfTotalItem(_ collageView: CollageView) -> Int {

        // total images count to show up
        return images.count
    }

    func collageViewNumberOfRowOrColoumn(_ collageView: CollageView) -> Int {

        // Sets number of total coloumn or row count of layout direction
        return 3
    }

    func collageViewLayoutDirection(_ collageView: CollageView) -> CollageViewLayoutDirection {

        // Sets the starting layout to fill images with
        // can be horizontol or vertical
        // if set to horizontal, first image rowIndex is (0, 0) and second one is (1, 0)
        // if set to vertical, first image rowIndex is (0, 0) and second one is (0, 1)

        return .horizontal
    }

    func collageView(_ collageView: CollageView, configure itemView: CollageItemImageView, at index: Int) {

        // MAGIC is in this code block
        // You can prepare your item here also,
        // You can fetch Images from Remote here!,
        // Customize UI for item, and etc..
        itemView.image = images[index]
        itemView.layer.borderWidth = 3
    }
}

extension ViewController: CollageViewDelegate {

    func collageView(_ collageView: CollageView, didSelect itemView: CollageItemImageView, at index: Int) {

        // Trigger click event of each image item
        let message = "didSelect at index:  (index), rowIndex: (String(describing: itemView.collageItem!.rowIndex))"
        print(message)
    }
}

Demo App Output

CollageViewCollageView

Installation

There are two ways to use CollageView in your project:

  • using CocoaPods
  • by cloning the project into your repository

Installation with CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the Get Started section for more details.

Podfile

use_frameworks!
pod 'CollageView', '~> 1.0.4'

Author

Ahmet Kazım Günay, [email protected]

License

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

Latest podspec

{
    "name": "CollageView",
    "version": "1.0.4",
    "summary": "Easy to use and fully customizable CollageView with multiple images inside.",
    "description": "Custom View, collageView implementation with pure Swift 4. This Library's aim is to make easily photo collage views.",
    "homepage": "https://github.com/ahmetkgunay/CollageView",
    "license": "MIT",
    "authors": {
        "Ahmet Kazu0131m Guu0308nay": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ahmetkgunay/CollageView.git",
        "tag": "1.0.4"
    },
    "social_media_url": "https://twitter.com/ahmtgny",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Source/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This