GithubHelp home page GithubHelp logo

colla2me / uicollectionviewflexlayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from devxoul/uicollectionviewflexlayout

0.0 1.0 0.0 35 KB

A drop-in replacement for UICollectionViewFlowLayout

License: MIT License

Swift 98.61% Ruby 1.39%

uicollectionviewflexlayout's Introduction

UICollectionViewFlexLayout

Swift CocoaPods Build Status Codecov

UICollectionViewFlexLayout is a drop-in replacement for UICollectionViewFlowLayout.

Features

  • Section Spacing
  • Section Margin
  • Section Padding
  • Section Background
  • Item Spacing
  • Item Margin
  • Item Padding
  • Item Size
  • Item Background
  • Item Z-Index

Basic Concept

Don't let cells have margins and paddings. Cell metrics are now set outside of the cell. Just focus on contents.

idea

Usage

UICollectionViewDelegateFlexLayout

protocol UICollectionViewDelegateFlexLayout {
  // section vertical spacing
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, verticalSpacingBetweenSectionAt section: Int, and nextSection: Int) -> CGFloat

  // section margin
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, marginForSectionAt section: Int) -> UIEdgeInsets

  // section padding
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, paddingForSectionAt section: Int) -> UIEdgeInsets

  // item horizontal spacing
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, horizontalSpacingBetweenItemAt indexPath: IndexPath, and nextIndexPath: IndexPath) -> CGFloat

  // item vertical spacing
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, verticalSpacingBetweenItemAt indexPath: IndexPath, and nextIndexPath: IndexPath) -> CGFloat

  // item margin
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, marginForItemAt indexPath: IndexPath) -> UIEdgeInsets

  // item padding
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, paddingForItemAt indexPath: IndexPath) -> UIEdgeInsets

  // item size
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, sizeForItemAt indexPath: IndexPath) -> CGSize

  // item z-index
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlexLayout, zIndexForItemAt indexPath: IndexPath) -> Int
}

Section and Item Background

// register
collectionView.register(MySectionBackgroundView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionBackground, withReuseIdentifier: "mySectionBackgroundView")
collectionView.register(MyItemBackgroundView.self, forSupplementaryViewOfKind: UICollectionElementKindItemBackground, withReuseIdentifier: "myItemBackgroundView")

// configure
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
  switch kind {
  case UICollectionElementKindSectionBackground: // section background
    return collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionBackground, withReuseIdentifier: "mySectionBackgroundView", for: indexPath)

  case UICollectionElementKindItemBackground: // item background
    return collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindItemBackground, withReuseIdentifier: "myItemBackgroundView", for: indexPath)

  case foo: // else
    return bar
  }
}

Tips and Tricks

  • Using with RxCocoa

    If you're using UICollectionView with RxSwift and RxCocoa, you should create an extension of _RXDelegateProxy class to support delegate proxy.

    import RxCocoa
    import UICollectionViewFlexLayout
    
    extension _RXDelegateProxy: UICollectionViewDelegateFlexLayout {
    }

Contributing

$ swift package generate-xcodeproj

License

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

uicollectionviewflexlayout's People

Contributors

devxoul avatar

Watchers

James Cloos 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.