GithubHelp home page GithubHelp logo

carabina / ktmosaiclayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ikiki/ktmosaiclayout

0.0 1.0 0.0 651 KB

A Swift UICollectionViewLayout to layout items on different columns.

License: MIT License

C 0.45% Swift 92.43% Shell 2.65% Ruby 4.47%

ktmosaiclayout's Introduction

KTMosaicLayout

Reusable

Xcode 9.0+ iOS 9.0+ tvOS 9.0+ Swift 4.0+ Version Carthage compatible License Twitter

KTMosaicLayout is a Swift UICollectionViewLayout being able to display UICollectionView items on different columns.

Features

In case at least 3 columns is defined for a section, KTMosaicLayout can display the first item of this section in a big style. When a section displays the first item as big, it means that the first row of this section displays all the last items on a single column, to layout the first as a big.

💡 In case you don't really need to display big styled items in sections as illustrated above, this layout can be replaced by a usual UICollectionViewFlowLayout.

📱Example

💡 To run the example project, clone the repo, pod install, and run the iOS application.

Installation

CocoaPods

The preferred installation method is with CocoaPods. Add the following to your Podfile:

pod 'KTMosaicLayout'

Carthage

For Carthage, add the following to your Cartfile:

github "iKiKi/KTMosaicLayout"

Usage

You just need to set a KTMosaicLayout to your UICollectionView layout (using IB or code), set a MosaicLayoutDelegate to this layout and implement the necessary methods:

public protocol MosaicLayoutDelegate: class {
  func collectionView(_ collectionView: UICollectionView, numberOfColumnsInSection section: Int) -> Int
  func collectionView(_ collectionView: UICollectionView, shouldShowBigInSection section: Int) -> Bool
  func collectionView(_ collectionView: UICollectionView, heightForItemInSection section: Int) -> CGFloat // Called in case more than 1 column
  func collectionView(_ collectionView: UICollectionView, heightForItemAt indexPath: IndexPath) -> CGFloat // Called in case only 1 column

  func collectionView(_ collectionView: UICollectionView, insetForSectionAt section: Int) -> UIEdgeInsets
  func collectionView(_ collectionView: UICollectionView, minimumLineSpacingForSectionAt section: Int) -> CGFloat
  func collectionView(_ collectionView: UICollectionView, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat

  func collectionView(_ collectionView: UICollectionView, referenceSizeForHeaderInSection section: Int) -> CGSize
  func collectionView(_ collectionView: UICollectionView, referenceSizeForFooterInSection section: Int) -> CGSize
}

💡 heightForItemInSection is called in case a section has more than 1 column. heightForItemAt is called in case the section has only 1 column (to layout items with different heights).

License

KTMosaicLayout is released under the MIT license. See LICENSE for details.

ktmosaiclayout's People

Contributors

ikiki avatar

Watchers

 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.