Git Product home page Git Product logo

collageview's Introduction

CollageView

Version License Platform Language Twitter: @ahmtgny

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

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

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.3'

Author

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

License

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

collageview's People

Contributors

ahmetkgunay avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.