Skip to content

dSunny90/SSAlignmentFlowLayout

Repository files navigation

SSAlignmentFlowLayout

📊 A lightweight, flexible UICollectionViewFlowLayout subclass for easily aligning cells per section with optional row limits.

SwiftPM compatible Swift Platform License: MIT


Features

  • Configure a single alignment for all sections, or use closures for section-specific logic.
  • Optionally limit the number of rows per section.
  • Integrates seamlessly with Interface Builder or programmatically.

Usage

// 1. Single static alignment for all sections
collectionView.collectionViewLayout = SSAlignmentFlowLayout(alignment: .left)

// 2. Dynamic alignment & row limit via closures (safe of retain cycles)
collectionView.collectionViewLayout = SSAlignmentFlowLayout(
    alignmentProvider: { [weak self] section in
        guard let self else { return .left }
        return self.alignment(for: section)
    },
    limitOfRowsProvider: { section in
        section == 0 ? 2 : 0
    }
)

Installation

SSAlignmentFlowLayout is available via Swift Package Manager.

Using Xcode:

  1. Open your project in Xcode
  2. Go to File > Add Packages…
  3. Enter the URL:
https://github.com/dSunny90/SSAlignmentFlowLayout
  1. Select the version and finish

Using Package.swift:

dependencies: [
    .package(url: "https://github.com/dSunny90/SSAlignmentFlowLayout", from: "1.0.0")
]

About

A layout object that organizes items with specific alignment, fixed spacing.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages