UICollectionViewFlowLayout subclass for precise horizontal & vertical cell alignment.
Drop-in replacement for UICollectionViewFlowLayout with granular alignment control. Unlike default flow layout (justified + center-aligned), this enables:
- Horizontal: left, right, leading, trailing, justified
- Vertical: top, center, bottom
| Option | Behavior | RTL Support |
|---|---|---|
.left |
Align to left edge | Fixed |
.right |
Align to right edge | Fixed |
.leading |
Align to start edge | ✓ Mirrors |
.trailing |
Align to end edge | ✓ Mirrors |
.justified |
Spread evenly (default) | N/A |
| Option | Behavior |
|---|---|
.top |
Align to top of row |
.center |
Center in row (default) |
.bottom |
Align to bottom of row |
dependencies: [
.package(url: "https://github.com/mischa-hildebrand/AlignedCollectionViewFlowLayout.git", from: "1.0.0")
]Copy AlignedCollectionViewFlowLayout.swift to your project.
import AlignedCollectionViewFlowLayout
let layout = AlignedCollectionViewFlowLayout(
horizontalAlignment: .left,
verticalAlignment: .top
)
collectionView.collectionViewLayout = layout- Add
UICollectionViewFlowLayoutto Collection View - Set Custom Class to
AlignedCollectionViewFlowLayout - Configure alignment in code:
if let layout = collectionView.collectionViewLayout as? AlignedCollectionViewFlowLayout {
layout.horizontalAlignment = .left
layout.verticalAlignment = .top
}layout.horizontalAlignment = .right
layout.verticalAlignment = .bottom
collectionView.collectionViewLayout.invalidateLayout()| Alignment | Preview |
|---|---|
| Left-aligned | ![]() |
| Right-aligned | ![]() |
| Justified | ![]() |
| Top-aligned | ![]() |
| Bottom-aligned | ![]() |
| Centered | ![]() |
- iOS 16.0+
- Swift 6.0+
- Xcode 14.0+
See Docs/APPLE_MAIL_STYLE.md for Apple Mail-style email chip implementation.
MIT License - See source file header for full text.
Copyright © 2017 Mischa Hildebrand





