Collapse and expand UICollectionView sections with one method call.

Overview

LOGO

Language Build Status codecov Version License Platform

This library provides a custom UICollectionView that allows to expand and collapse sections. Provides a simple API to manage collection view appearance.

CampcotCollectionView

Requirements

  • iOS 9.0+
  • Xcode 10.2+
  • Swift 5.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate CampcotCollectionView into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'CampcotCollectionView'
end

Then, run the following command:

$ pod install

Usage

Manual Setup

import CampcotCollectionView
  1. Create CollectionView
let campcotCollectionView = CampcotCollectionView()
  1. Add campcotCollectionView to view hierarchy.
  2. Call toggle method on campcotCollectionView.
public func toggle(to section: Int,
                   offsetCorrection: CGFloat = default,
                   animated: Bool,
                   completion: ((Bool) -> Void)? = default)

Storyboard Setup

  1. Add UICollectionView to your Storyboard.
  2. In Identity Inspector set the Class property to CampcotCollectionView.
  3. Open Attributes Inspector and set the Layout property to Custom. Set Class property to either ExpandedLayout or CollapsedLayout.
  4. Create outlet for your collectionView.
  5. Set datasource and delegate for collectionView.
  6. Set the settings for collectionView in Attributes Inspector or manualy.

Documentation

CampcotCollectionView

A Boolean value that determines whether the sections are expanded.

public var isExpanded: Bool { get }

Expands all the sections. Pins a section at index section to the top of view bounds. offsetCorrection - the offset for pinned section from the top. Default value of offsetCorrection is 0. animated - if true expands sections with animation. completion - callback for animation.

public func expand(from section: Int,
                   offsetCorrection: CGFloat = default,
                   animated: Bool,
                   completion: ((Bool) -> Void)? = default)

Collapses all the sections. Pins a section at index section to the top of view bounds. offsetCorrection - the offset for pinned section from the top. Default value of offsetCorrection is 0. animated - if true collapses sections with animation. completion - callback for animation.

public func collapse(to section: Int,
                     offsetCorrection: CGFloat = default,
                     animated: Bool,
                     completion: ((Bool) -> Void)? = default)

Toggles current state from collapsed to expaned and vise versa. Pins a section at index section to the top of view bounds. offsetCorrection - the offset for pinned section from the top. Default value of offsetCorrection is 0. animated - if true toggles sections with animation. completion - callback for animation.

public func toggle(to section: Int,
                   offsetCorrection: CGFloat = default,
                   animated: Bool,
                   completion: ((Bool) -> Void)? = default)

Comments
  • Integrate SwiftFormat in CampcotCollectionView

    Integrate SwiftFormat in CampcotCollectionView

    • Added script for formatting CampcotCollectionView and Example projects.
    • Added a Build phase for linter support.
    • Added .swiftformat configuration file.
    opened by AlexYanski 2
  • Fix Fatal error: Division by zero in remainder operation

    Fix Fatal error: Division by zero in remainder operation

    This fixes Thread 1: Fatal error: Division by zero in remainder operation when for some reasons prepare() method is called with zero contentWidth.

    I was working on my custom fork where the collectionView should automatically calculate its size based on the Intrinsic content size. Then After awhile I was greeted by the mentioned error. Refer to the screenshot below.

    Screen Shot 2021-02-21 at 1 43 50 PM

    I fixed the issue by preventing further calculations unless the columnsCount is greater than zero.
    So I thought it will be a great addition if it doesn't break any of your calculations. (So far it doesn't break anything based on my use case).

    opened by MussaCharles 1
  • Bug: state of self.isExpanded is incorrect on startup

    Bug: state of self.isExpanded is incorrect on startup

    Nice package and it mostly works fine but, Using this package causes the following

    1. the collectionView starts as open despite calling view.collapse in ViewWillAppear
    2. user needs to tap a header twice (only the first time) to collapse the collection. After the first collapse, the sections accordion appropriately with a single tap.

    Finding: in calling the method "collapse" the first time, when app opens, the internal flag "isExpanded" is set to false despite the collection being defaulted to fully expanded.

    I can not find where you initialize your isExpanded var, but you should probably have an optional init which passes the desired state.

    opened by 224XS 1
  • Support storyboard

    Support storyboard

    Hello, I tried to use the CampcotCollectionView in storyboard but couldn't. I ran into this error

    required public init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
    }
    

    Could you please help fix that. Thank you!

    opened by tony-hoang999 1
  • Bottom inset correction

    Bottom inset correction

    Add property contentSizeAdjustmentBehavior that allows to setup how contentSize will be calculated. It fixes problem when collection view has insets and content can be scrolled out of bounds.

    opened by VadzimMarozau 1
Releases(0.0.8)
Owner
Touchlane
Making custom software for you
Touchlane
An iOS drop-in UITableView, UICollectionView and UIScrollView superclass category for showing a customizable floating button on top of it.

MEVFloatingButton An iOS drop-in UITableView, UICollectionView, UIScrollView superclass category for showing a customizable floating button on top of

Manuel Escrig 298 Jul 17, 2022
Automates prefetching of content in UITableView and UICollectionView

Automates preheating (prefetching) of content in UITableView and UICollectionView. Deprecated on iOS 10. This library is similar to UITableViewDataSou

Alexander Grebenyuk 633 Sep 16, 2022
A data-driven UICollectionView framework for building fast and flexible lists.

A data-driven UICollectionView framework for building fast and flexible lists. Main Features ?? Never call performBatchUpdates(_:, completion:) or rel

Instagram 12.5k Jan 1, 2023
Netflix and App Store like UITableView with UICollectionView, written in pure Swift 4.2

GLTableCollectionView Branch Status master develop What it is GLTableCollectionView is a ready to use UITableViewController with a UICollectionView fo

Giulio 708 Nov 17, 2022
Incremental update tool to UITableView and UICollectionView

EditDistance is one of the incremental update tool for UITableView and UICollectionView. The followings show how this library update UI. They generate

Kazuhiro Hayashi 90 Jun 9, 2022
🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.

A declarative library for building component-based user interfaces in UITableView and UICollectionView. Declarative Component-Based Non-Destructive Pr

Ryo Aoyama 1.2k Jan 5, 2023
Protocol-oriented UICollectionView management, powered by generics and associated types.

DTCollectionViewManager Features Powerful mapping system between data models and cells, headers and footers Automatic datasource and interface synchro

Denys Telezhkin 308 Jan 6, 2023
UICollectionView layout for presenting of the overlapping cells.

StickyCollectionView UICollectionView layout for presenting of the overlapping cells. Objective-C version here Checkout demo Overview Installation Man

Bogdan Matveev 325 Oct 11, 2022
A generic small reusable components for data source implementation for UITableView/UICollectionView in Swift.

GenericDataSource A generic small reusable components for data source implementation for UITableView/UICollectionView written in Swift. Features Basic

null 132 Sep 8, 2021
Reimagining UICollectionView

CollectionKit Reimagining UICollectionView A modern Swift framework for building composable data-driven collection view. Migration Guide v2.0 Features

SoySauceLab 4.3k Dec 27, 2022
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 157 Nov 25, 2022
ZHTCView - UITableview & UICollectionView

ZHTCView 这是一个使用Block替换代理的UITableview & UICollectionView。 使用方法如下: - (DSTableView *)tableView { if (!_tableView) { _tableView = DSTableView.

黑酒一 0 Jan 10, 2022
CollectionView - UICollectionView using UICollectionViewCompositionalLayout

CollectionView UICollectionView using UICollectionViewCompositionalLayout create

null 0 Jan 11, 2022
CollectionViewSegmentedControl - Scrollable UISegmentedControl built using a UICollectionView

CollectionViewSegmentedControl Installation CocoaPods Download CocoaPods Run 'Po

James Sedlacek 7 Nov 24, 2022
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 155 May 12, 2022
A modest attempt to port UICollectionView to SwiftUI.

LazyCollectionView A modest attempt to port UICollectionView to SwiftUI. Table of Contents Description Requirements Installation Usage Components Impr

Unsplash 109 Dec 27, 2022
Easy and type-safe iOS table and collection views in Swift.

Quick Start TL;DR? SimpleSource is a library that lets you populate and update table views and collection views with ease. It gives you fully typed cl

Squarespace 96 Dec 26, 2022
A SwiftUI collection view with support for custom layouts, preloading, and more.

ASCollectionView A SwiftUI implementation of UICollectionView & UITableView. Here's some of its useful features: supports preloading and onAppear/onDi

Apptek Studios 1.3k Dec 24, 2022
A Swift mixin for reusing views easily and in a type-safe way (UITableViewCells, UICollectionViewCells, custom UIViews, ViewControllers, Storyboards…)

Reusable A Swift mixin to use UITableViewCells, UICollectionViewCells and UIViewControllers in a type-safe way, without the need to manipulate their S

Olivier Halligon 2.9k Jan 3, 2023