Giter VIP home page Giter VIP logo

admozaiccollectionviewlayout's Introduction

ADMozaicCollectionViewLayout

Carthage compatible CocoaPods Compatible codebeat badge

What is it

ADMozaicCollectionViewLayout is yet another UICollectionViewLayout subclass that implements "brick" or "mozaic" layout.

example

Why do anybody need yet another one?

Because there are plenty of kind of the same layouts already:

But this project is pure swift implementation, so if you don't want to mess up objective-c code and swift you are on the right page. Also, as an advantage compares to another "mozaic" layout - you're not limited to predefined sizes of cells.

Usage

The idea behind this layout is to split UICollectionView bounds into some kind of "matrix". To do this ADMozaikCollectionViewLayout requires height for rows and width for columns.

/**
 Designated initializer to create new instance of `ADMozaikLayout`
     
 - parameter rowHeight: height for each row
 - parameter columns:   array of `ADMozaikLayoutColumn` for the layout
     
 - returns: newly created instance of `ADMozaikLayout`
 */
public init(rowHeight: CGFloat, columns: [ADMozaikLayoutColumn])

Where ADMozaikLayoutColumn is the column description

/**
 *  Defines the layout's column
 */
public struct ADMozaikLayoutColumn {
    /// Width of the column in points
    let width: CGFloat
}

Also, it requires the delegate object that is conformed to protocol ADMozaikLayoutDelegate to get the size of each cell

/**
 Method should return `ADMozaikLayoutSize` for specific indexPath
     
 - parameter collectionView: collection view is using layout
 - parameter layout:         layout itself
 - parameter indexPath:      indexPath of an item for the size it asks for
 
 - returns: `ADMozaikLayoutSize` struct object describes the size
 */
func collectionView(collectionView: UICollectionView, layout: UICollectionViewLayout, mozaikSizeForItemAtIndexPath indexPath: NSIndexPath) -> ADMozaikLayoutSize

Where ADMozaikLayoutSize describes the size of each cell in terms of ADMozaikCollectionViewLayout

/**
 *  Defines the size of the layout item
 */
public struct ADMozaikLayoutSize {
    /// Columns number that item requires
    let columns: Int
    /// Rows number that item requires
    let rows: Int
}

For the complete example please check the example project. Note that current example project is supposed to be run on iPhone 6 screen's size.

Limitation

This is the early bird release so this layout doesn't support headers, footers and sections at the moment. It's on my roadmap but PRs are very welcome=)

Easy to install

CocoaPods

To integrate ADPuzzleAnimation 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 'ADMozaicCollectionViewLayout', '~> 1.0.0'

Carthage

To integrate ADMozaicCollectionViewLayout into your Xcode project using Carthage, specify it in your Cartfile:

github "Antondomashnev/ADMozaicCollectionViewLayout" ~> 1.0

Run carthage update to build the framework and drag the built ADMozaikCollectionViewLayout.framework into your Xcode project.

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.