Computes a perfectly justified collection of elements for any given width while maintaining the source aspect ratio. This library aims to mimic the layout implementations found in:
At it's core, Lay applies the linear partitioning algorithm against the aspect ratios of each size element to compute the balanced layout.
- No cropping, source size aspect ratios will be maintained.
- Flexible, works with any array of elements that conform to the
Sizableprotocol. - Swift 3.0
Checkout out the Example app to see how this can be integrated with UICollectionViews.
This project is heavily inspired by this article written by Johannes Treitz.
import Lay
let aspectRatios: [CGSize] = [
.init(width: 100, height: 100),
.init(width: 80, height: 120),
.init(width: 100, height: 100),
.init(width: 200, height: 200),
.init(width: 80, height: 100),
.init(width: 100, height: 120),
.init(width: 100, height: 80)
]
// Can now use these sizes to render your elements however you want
let sizes: [CGSize] = aspectRatios.lay_justify(for: view.bounds.size.width)
>>> [
(140.0, 140.0),
(93.0, 140.0),
(142.0, 140.0),
(208.0, 208.0),
(167.0, 208.0),
(150.0, 180.0),
(225.0, 180.0)
]- Tests
- Cocoapods support
- Xcode 8.0+
- iOS 9.0+
- Swift 3.0
For Carthage, add the following to your Cartfile:
github "min/Lay" ~> 0.1.0

